Great, that answers my question. Thanks Jeremy. On Mar 4, 3:56 pm, Jeremy Evans <[email protected]> wrote: > On Mar 4, 2:20 pm, jv27243 <[email protected]> wrote: > > > > > > > I'm having a problem removing an object via assocation remove_, and > > wanted to make sure I'm doing things properly. > > > Here are how my models are declared: > > > class A < Sequel::Model(:a) > > set_primary_key :a_id > > :one_to_many :bobjects, :class =>:B, :key =>:b_id, :primary_key > > =>:a_id > > end > > > class B < Sequel::Model(:b) > > set_primary_key :b_id, :c_id > > end > > > When I call: > > > a = A[1] > > b = B[1,2] > > > a.remove_b(b) # this results in update nil/NULL is not allowed for > > the :b_id column > > > I tried setting b.raise_on_typecast_failure=false before calling > > remove but it doesn't remove the entry at all. I wanted to make sure > > I'm using this method properly. Thoughts? > > Unfortunately, what you want isn't possible. You have an association > from A's primary key to one of two primary keys in B. How remove > works is by setting the key of the associated object to NULL and > saving it. Unfortunately, you can't do that if the column is a > primary key. I would recommend writing your own _remove_b method to > do what you want. > > You should note that remove in this context means remove the object > from the association (disassociate), rather than remove from the > database (delete). If you want to delete the associated object, just > call b.destroy instead of a.remove_b, or have your _remove_b method do > the destroy: > > def _remove_b(b) > b.destroy > end > > Jeremy
-- You received this message because you are subscribed to the Google Groups "sequel-talk" group. 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.
