On Friday, May 2, 2014 8:49:25 AM UTC-7, Jef Harkay wrote:
>
> Genius! So my create code becomes this:
>
> model = Author.new(:name => "blah")
> model.save
> model.book_pks = [1, 2, 3, 4, 5]
>
>
> And update is similar... but that *.save* is essential, otherwise, I
> don't have a primary key (author_id) to insert with the book_id. Thanks
> for the help, Jeremy!
>
Correct. nested_attributes uses a plugin called instance_hooks to delay
the association stuff until after the save:
model = Author.new(:name => "blah")
model.after_save_hook{model.book_pks = [1, 2, 3, 4, 5]}
model.save
I wouldn't use it in your case, but for more complex cases it is pretty
helpful.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.