-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create associate items #216
Comments
Does your |
No it doesn't. Thats why I've written the hook. Should it? I cant see it in
|
... also the two pets are created after the person because they reference
|
They might be created after the owner to be able to have the owner id set. But what I meant was if the callback is called after the owner is created or after everything is created? |
The callback e.g. the one on Person.create ([...], callback) does not wait
|
Yes, |
Its just the Person, with no pets. I'll add a new test case if this isn't the expected behavior. |
Can you try using the var John = new Person({
name: "John",
pets: [ /* ... */ ]
});
John.save(/* ... */); I think this works as expected. Maybe the only thing that is not is the different behaviour of |
Its not working for me. here's my test case. John is inserted into the 'person' table but his pet Fido is not inserted into the 'animal' table.
|
Try changing |
Ah ok, so it can dish it* out but it can't take it* (*json).... pardon the joke. That's what i thought. Any chance this could be a future feature? |
Yes, I'll update this. I was just trying to understand if the problem was that or not. |
…ciations (#216) Adds initial tests for Model.create(), deprecates old one
Please try and tell if it's working now with the latest commit. |
I get these two inserts
The second one is missing the name. |
I didn't realize you made a hasOne association on animal with reverse and saving it using person. I'm debugging right now. |
If you change your code to this, it works: // Define associate
John.pets = {
name : "Fido"
}; A reverse association of hasOne is creating another hasOne so you can't use an Array. |
What you want makes sense but the |
I think I got it, I'm posting a fix in a moment. Nevermind about my previous comment, it should behave as you're thinking about it. |
Hey that's great (orm/mysql) INSERT INTO fyi: cloning on windows and running "npm install" breaks on sqlite, somehow 'npm update' works though. I'm not too familiar with npm. How long until these fixes are available in npm? |
|
If you're using sqlite3 > 2.1.7, downgrade it to this version. Later ones have some problems on some obscure queries. |
With the autoFetch attribute, nested items are retrieved from associated tables.
Is it possible to have the same work for post, e.g if i were to post
It would write items to the model which was associated with 'pets'
I found a work around using afterCreate hook e.g.
However i'd like it to be a little more abstract and have it know the reference to the child in question, e.g. not have to explicitily define it like i do with...
this[x][i]['owner_id'] = this.id;
Also i'd only like it to trigger the callback if this has been completed successfully. But there is no "next" parameter passed to this particular hook.
Thanks in advance, great project.
The text was updated successfully, but these errors were encountered: