On Monday, March 5, 2018 at 12:59:05 PM UTC-7, Jeremy Evans wrote:
>
> On Monday, March 5, 2018 at 10:56:33 AM UTC-8, James wrote:
>>
>> Hi,
>>
>> I'm looking for an example as to how to use the validate_associated 
>> plugin.  Here's an example of what I'm trying to do.
>>
>> class Address < Sequel::Model
>>   plugin :validation_helpers
>>   
>>   many_to_one :sales_order, key: :link_no, primary_key: :order_no
>>
>>   def validate
>>     super
>>     validates_presence :name
>>   end
>> end
>>
>> class SalesOrder < Sequel::Model
>>   plugin :validation_helpers
>>   plugin :validate_associated
>>   
>>   one_to_one :shipping_address, class: Address, conditions: {addr_type: 
>> 'S'}, key: :link_no, primary_key: :order_no
>>
>>   private
>>
>>   def validate
>>     super
>>     validates_presence [..., ..., ...]
>>   end
>> end
>>
>> so = SalesOrder[1234]
>> so.shipping_address.name = nil
>> so.valid?  #  true  (expected false because shipping_address.name is not 
>> present)
>>
>
> The plugin itself does not change behavior, it merely adds the 
> Model#validate_associated_object method that can be called to validate the 
> associated object.  I can see where the current documentation is lacking in 
> how to use it directly, it was mostly decided for use by other plugins such 
> as nested_attributes and delay_add_association.  I'll update the 
> documentation shortly to provide a clearer example of usage.
>
>
Thank you!  The new documentation is much more helpful.  :) 

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to