Simple one to many definition that doesn't work

67 views
Skip to first unread message

Ken Rozenes

unread,
Mar 17, 2011, 10:51:27 AM3/17/11
to persistence.js
Hi,

I'm a new in persistence.js, and when I try to build my simple
application I ran into this problem.
I declare for:

var CrewMember = null;
var Event = null;

CrewMember = persistence.define('CrewMember',
{
name: "TEXT",
ind: "INT"
});

Event = persistence.define('Event',
{
name : "TEXT",
date : "DATE"
});

Event.hasMany('crew', CrewMember, 'event');

persistence.schemaSync(function(tx)
{
$("#container").append("Created" + "<br><br><br>");
});

Everything is ok until here and the database is created.
But when I'm trying to insert objects into persistence like this:

var myname = "Ken";

var crew_member = new CrewMember({name : myname, ind: ++index});
persistence.add(crew_member);

var current_date = new Date();
var myevent = new Event({name : "My Event", date: current_date})

myevent.crew.add(crew_member); /* Here it stops - "add" function
not found */

persistence.add(myevent);

persistence.flush();

The debugger notifies in the marked line that there is no "add"
function in "crew".
It seems like no QueryCollection object never created for the 'crew'
field.

Any help will be appreciated..

Thanks,
Ken

Zef Hemel

unread,
Mar 17, 2011, 11:04:15 AM3/17/11
to persis...@googlegroups.com
Hi Ken,

I just tried to code and seems to work just fine for me. One thing
that can potentially be wrong is the moment you execute the code
block:

>                        var myname = "Ken";
>
>                        var crew_member = new CrewMember({name : myname, ind: ++index});
>                        persistence.add(crew_member);
>
>                        var current_date = new Date();
>                        var myevent = new Event({name : "My Event", date: current_date})
>
>                        myevent.crew.add(crew_member);  /* Here it stops - "add" function
> not found */


When is this code executed? Are you sure the schemaSync has finished
executing by then, for instance?

Zef

--
Zef Hemel
http://zef.me
http://twitter.com/zef

Ken Rozenes

unread,
Mar 17, 2011, 12:56:03 PM3/17/11
to persistence.js
Hi Zef,

Thank you for your quick answer.
Yes. schemaSync has finished. The callback function was activated and
I saw the schema in my debugger.
This is my "fool around" file:
http://www.speedyshare.com/files/27453196/exp.html

I'll be happy if you'll check it . I'll also like to see what I did to
make it work, maybe there is something else that is wrong.

Thanks again,
Ken

Ken Rozenes

unread,
Mar 17, 2011, 3:32:59 PM3/17/11
to persistence.js
Hi Zef,

I found out what the problem was.
Something is wrong in the jQuery plugin, because when I didn't include
it everything work fine.
There must be something that overrides this functionality in this
plugin.

I really appreciate your help.

Yours,
Ken

Ryan

unread,
Apr 17, 2011, 12:33:47 AM4/17/11
to persistence.js
I can confirm the same behaviour. The JQuery plugin seems to be the
problem.

GauravM

unread,
Jun 4, 2011, 12:04:30 AM6/4/11
to persistence.js
Hello after the save were you able to query this from the one side
that is when you retrieve an event you get all the associated crew;
can you share code for that?

Thanks
Gaurav M
Reply all
Reply to author
Forward
0 new messages