add scoped finders
-
Chris Wanstrath
- State changed from new to invalid
The plan is for Ambition to only support the Ruby Enumerable API. You're welcome to write an add-on which supports this, though.
-
Grant Rodgers
went ahead and wrote this. Rather small amount of code.
-
Grant Rodgers
works like this:
class User < ActiveRecord::Base scoped_context :admins do |context| context.select { |u| u.type == 'Admin' } end end User.admins.to_sql #=> "SELECT * FROM users WHERE users.type = 'Admin'" -
Grant Rodgers
Not sure how add-ons are packaged, unfortunately - let me know if there's something else to be done.
-
Chris Wanstrath
You can do this already, y'know:
class Company def self.high_rated query_context.select { |c| c.rating > 3 } end end >> Company.high_rated.to_sql => "SELECT * FROM companies WHERE companies.`rating` > 3" >> Company.high_rated.first => #<Company:0x26eb1ec ...> -
Chris Wanstrath
Maybe this is worth posting about.
-
Grant Rodgers
Yep, that occurred to me. Certainly a matter of taste which you prefer.
I think it might be a bit better encapsulated as a special method, and maybe faster since it doesn't go through the query processor for every call.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
