On Friday, March 23, 2012 8:58:09 AM UTC-7, Jamie Hodge wrote:
>
> I was under the impression that association_pks could be used for new
> (unsaved) objects, but when I call setter methods, it immediately
> attempts to create join tables, sans id. Is this the correct behavior?
> Am I missing something or are these methods only appropriate for saved
> objects?
>
In general, associations modification methods other than the many_to_one
setter method only work on saved objects (since they need a primary key,
and new objects generally don't have one). In association_pks case, it
needs to access the underlying dataset (@this), and new objects don't have
a dataset, since there is no row in the database that represents them yet.
The usual way to work around this would be to use the instance hooks plugin
to delay calling the association_pks= method until after the object has
been saved:
model.after_create_hook{model.association_pks = [1, 2, 3, ...]}
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/HdZSsTCynzkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.