Reputation: 4167
I'm trying to build a small app, for learning purposes, using Dart, MongoDB and Objectory. For that I've created a basic model:
part of myapp;
class Member extends PersistentObject {
String get username => getProperty('username');
set username(String value) => setProperty('username',value);
String get password => getProperty('password');
set password(String value) => setProperty('password',value);
// more fields here
}
void registerClasses() {
objectory.registerClass(Member, () => new Member());
}
And inside my main app file I have:
library myapp;
import "package:redstone/server.dart" as app;
import "package:objectory/objectory.dart";
import "dart:core";
part "lib/member.dart";
Objectory objectory;
void main() {
objectory = new Objectory("mongodb://localhost/myapp", registerClasses, false);
objectory.initDomainModel().then((_) {
app.setupConsoleLog();
app.start(address: "127.0.0.1", port: 8080);
});
}
And when I run it I get the follwing error:
Breaking on exception: object of type NoSuchMethodError
Unhandled exception:
The null object does not have a method 'dataMapDecorator'.
NoSuchMethodError: method not found: 'dataMapDecorator'
Receiver: null
Arguments: [Instance of '_LinkedHashMap']
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1 BasePersistentObject.BasePersistentObject (package:objectory/src/persistent_object.dart:10:46)
#2 PersistentObject.PersistentObject (package:objectory/src/persistent_object.dart:1:1)
#3 Member.Member (file:///Users/lucian/Projects/dart/eviq/bin/lib/member.dart:1:1)
#4 registerClasses.<anonymous closure> (file:///Users/lucian/Projects/dart/eviq/bin/lib/member.dart:74:45)
#5 Objectory.registerClass (package:objectory/src/objectory_base.dart:118:39)
#6 registerClasses (file:///Users/lucian/Projects/dart/eviq/bin/lib/member.dart:74:26)
#7 Objectory.initDomainModel (package:objectory/src/objectory_base.dart:141:28)
#8 main (file:///Users/lucian/Projects/dart/eviq/bin/eviq.dart:13:28)
#9 _startIsolate.isolateStartHandler (dart:isolate-patch/isolate_patch.dart:216)
#10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:124)
Any idea of what I'm doing wrong? Thanks.
Upvotes: 1
Views: 110
Reputation: 1516
You are instatiating base Objectory class. There is concrete implementatins of Objectory for server side and browser environment.
Assuming that you are trying to use Objectory on server side you should use ObjectoryDirectConnectionImpl
see https://github.com/vadimtsushko/objectory/blob/master/example/console/blog_console.dart for example
library blog_example;
import 'package:objectory/objectory_console.dart';
import '../domain_model/domain_model.dart';
const Uri = 'mongodb://127.0.0.1/objectory_blog';
main(){
objectory = new ObjectoryDirectConnectionImpl(Uri,registerClasses,true);
var authors = new Map<String,Author>();
var users = new Map<String,User>();
objectory.initDomainModel().then((_) {
Third parameter of ObjectoryDirectConnectionImpl
constructor command objectory to drop collections after opening db - usefull for samples and tests, you probably should make it false
Upvotes: 2