Re: [Rails] Chain scopes with OR
try
escopo: find_visibles, lambda { find_in_coverage.find_know_missing}
2012/5/21 Gustavo de Sá Carvalho Honorato <gustavohonorato@gmail.com>
The problem of the first solution is that "find_in_coverage | find_known_missing" combined that way does not return a scope. It returns two arrays each and applies | operator on the result. See: http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-7CI've looked arel docs (in fact, I just found poor docs). Can you please point me where in docs is explaining how I can construct such query?Thanks for you attention,GustavoOn Fri, May 18, 2012 at 3:52 PM, azizmb.in <me@azizmb.in> wrote:
To add to that, if you want to construct complex queries, you should have a look at arel.On Sat, May 19, 2012 at 12:17 AM, azizmb.in <me@azizmb.in> wrote:
AFAIK, something like this should work:def find_visiblesfind_in_coverage | find_known_missingend--On Fri, May 18, 2012 at 10:53 PM, Gustavo de Sá Carvalho Honorato <gustavohonorato@gmail.com> wrote:
Hi all!I've googled all over and I couldn't find anything about chaining scopes with OR instead of the default AND.I have an Asset model with the following scopes:class Asset < ActiveRecord::Base(...)scope :find_in_coverage, lambda { where('timestamp(assets.found_at) >= ?', Asset.found_at_limit) }scope :find_unknown_in_coverage, where('assets.asset_type_id IS NULL').find_in_coveragescope :find_known_missing, lambda { where('assets.found_at < ? AND assets.asset_type_id IS NOT NULL', Asset.found_at_limit) }endI would like to create another scope ("find_visibles") which is the OR of "find_in_coverage" and "find_known_missing" scopes, like that:scope :find_visibles, find_in_coverage.find_know_missingThe problem is that this method chain uses AND to concatenate WHERE clauses. I need this clauses to be concatenated using OR instead.How can I do that?Thanks in advance,Gustavo Honorato--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
- Aziz M. Bookwala
--
- Aziz M. Bookwala
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
att,
Rogerio
A complicação se descomplica na mesma proporção que fazemos os nós se desatarem ao tecer o conhecimento do saber.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home