Simple one to many definition that doesn't work

Showing 1-6 of 6 messages
Simple one to many definition that doesn't work Ken Rozenes 3/17/11 7:51 AM
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
Re: [persistence.js] Simple one to many definition that doesn't work Zef Hemel 3/17/11 8:04 AM
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

Re: Simple one to many definition that doesn't work Ken Rozenes 3/17/11 9:56 AM
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
Re: Simple one to many definition that doesn't work Ken Rozenes 3/17/11 12:32 PM
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
Re: Simple one to many definition that doesn't work Ryan 4/16/11 9:33 PM
I can confirm the same behaviour.  The JQuery plugin seems to be the
problem.
Re: Simple one to many definition that doesn't work GauravM 6/3/11 9:04 PM
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