On Tuesday, June 23, 2015 at 10:29:32 AM UTC-7, Andrew Burleson wrote:
>
> Just to be clear the final syntax should be like this:
>
> WorkOrder.one_to_many :jobs, key: [:worker_id, :schedule_id], primary_key: 
> [:worker_id, :schedule_id]
> Job.many_to_one :work_order, key: [:worker_id, :schedule_id], primary_key: 
> [:worker_id, :schedule_id]
>

That looks right.
 

> A follow up question, if I've got another association that works like this:
>
> Order.many_to_one :property
> Order.many_to_one :service
> Order.one_through_one :city, :join_table=>:properties, :left_key=>:id, 
> :left_primary_key=>:property_id, :right_key=>:city_id
>
> Property.many_to_one :city
> City.one_to_many :offers
>
>
> Offer.many_to_one :city
> Offer.many_to_one :service
>
> I can load the Offer for the Order similar to a compound key: 
> Offer.where(city: order.city, service: order.service)
>
> But in this case there's no city_id on the order itself, the city_id 
> belongs to the joined community. Is it possible to connect Order <-> Offer 
> as a sequel model association?
>

It's possible, and if you only want to handle simple cases, not that 
difficult:

class Order
  def city_id
    city.id if city
  end
end
Order.many_to_one :offer, :key=>[:city_id, service_id], 
:primary_key=>[:city_id, :service_id], :read_only=>true

That should work assuming you don't have to eagerly load the association. 
 If you do have to eagerly load the association, it's much more complex, 
you'd need to write a custom eager loader to handle it 
(see 
http://sequel.jeremyevans.net/rdoc/files/doc/advanced_associations_rdoc.html).

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