On Tuesday, August 26, 2014 5:32:46 AM UTC-7, [email protected] wrote:
>
> Hello everybody.
>
> Take this code into account:
>
> ----------------------------------------------------------------------
> class Foo < Sequel::Model
>   one_to_many :bars
>   nested_attributes :bars
>
>   def validate
>     super
>     errors.add "Ble..." if bars.size < 2
>   end
> end
>
> class Bar < Sequel::Model
>   many_to_one :foo
> end
> -----------------------------------------------------------------------
>
> If you use nested_attributes for creating a Foo entity with 2 bars all  is 
> good. Later, when you try to update it deleting one bar, validation gives 
> you an error, because before saving model (in validation step) Foo object 
> has not deleted yet removed data, so bars.size continues being 2.
>
> Model consistency after nested_attributes updating is kept for all changes 
> except deletions with ":_delete => true" semantics. Ia have fixed that in 
> my system with a wrapper plugin above nested_attributes and others, but it 
> seems that inconsistency is bad behaviour for base Sequel.
>
> What do you think about it?
>

I guess there is a slight inconsistency in that area.  Currently if _delete 
or _remove keys are given, Sequel only adds the appropriate before/after 
save hook depending on when the deletion should happen.  I suppose at that 
point we could remove the object from the cached array, so future attempts 
to load the objects will reflect the fact that the object has been deleted, 
even if it hasn't been committed to the database yet.  I'll add that to my 
todo list.

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.

Reply via email to