Thanks, that's great.

Is there any way to invert the :conditions hash (that is, to be able to use a != or NOT IN in one of the conditions)? It's obviously possible to do with a block, but I was just wondering if I could do it with the same eager loading benefits and terser syntax.

Best,
Rob

On 6 Sep 2013, at 15:50, Jeremy Evans wrote:

On Friday, September 6, 2013 7:04:13 AM UTC-7, Rob Miller wrote:

I realised, in the time it took my post to appear, that this is absolutely possible to model in Sequel, and is in fact quite straightforward; you
simply pass a block to the association:

one_to_many :attachments, :key => :post_parent, :class => self do |ds|
ds.where(:post_type => 'attachment')
end

Hope this is useful to someone else who's in the same position as me! (And please do let me know if it isn't the most efficient/best way to do things.)

While you can use a block, in this case it may be easier to use :conditions:

one_to_many :attachments, :key => :post_parent, :class => self, :conditions=>{:post_type => 'attachment'}

Other than succinctness, the advantages are that eager loading via eager_graph will automatically work correctly.

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/groups/opt_out.

--
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/groups/opt_out.

Reply via email to