Rails 2.3: How to turn this SQL statement into a named_scope

Posted by randombits on Stack Overflow See other posts from Stack Overflow or by randombits
Published on 2010-05-30T04:28:45Z Indexed on 2010/05/30 8:42 UTC
Read the original article Hit count: 189

Filed under:
|
|

Having a bit of difficulty figuring out how to create a named_scope from this SQL query:

select * from foo where id NOT IN (select foo_id from bar) AND foo.category = ? ORDER BY RAND() LIMIT 1;

Category should be variable to change.

What's the most efficient way the named_scope can be written for the problem above?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby