I'm pretty sure I did. In the nested_attributes.rb code I see the method responsible:
def nested_attributes_setter(reflection, attributes) return if (b = reflection[:nested_attributes][:reject_if]) && b.call(attributes) modified! klass = reflection.associated_class if pk = attributes.delete(klass.primary_key) || attributes.delete(klass.primary_key.to_s) if klass.db.send(:typecast_value_boolean, attributes[:_delete] || attributes['_delete']) && reflection[:nested_attributes][:destroy] nested_attributes_remove(reflection, pk, :destroy=>true) elsif klass.db.send(:typecast_value_boolean, attributes[:_remove] || attributes['_remove']) && reflection[:nested_attributes][:remove] nested_attributes_remove(reflection, pk) else nested_attributes_update(reflection, pk, attributes) end else nested_attributes_create(reflection, attributes) end end It appears that the block within the conditional: if pk = attributes.delete(klass.primary_key) || attributes.delete(klass.primary_key.to_s) will only perform a remove or update operation. The create operation appears to only ever happen in the case where there is no PK specified. This would explain the behaviour I was observing. Cheers Josh On Tuesday, 15 February 2011 at 8:55 AM, Jeremy Evans wrote: > On Feb 14, 1:50 pm, Josh Bassett <[email protected]> wrote: > > Howdy, > > > > I've been trying to use the nested_attributes plugin for a particular > > use-case: I want to create a nested model *and* specify its primary > > key. > > Do you have unrestrict_primary_key for the associated model class? If > not, you should: > > Album.unrestrict_primary_key > > 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. > -- 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.
