Rails 2.3: How to create this SQL 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
            4:32 UTC
        
        
        Read the original article
        Hit count: 319
        
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