Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

add scoped finders

#105

It would be really cool if Ambition had scoped finders, ala scope_out, has_finder, and scoped_proxy

Combining nested scopes with kicker methods would do wonders I think:

Article.published.popular.first

select * from articles where (published = 1) AND (popular = 1) LIMIT 1

Reported by Grant Rodgers · September 6th, 2007 @ 04:55 PM

State: invalid
Milestone: none
Assigned to: Chris Wanstrath Chris Wanstrath

Activity

  1. Chris Wanstrath
    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.

    September 16th, 2007 @ 12:36 PM

  2. Grant Rodgers
    Grant Rodgers

    went ahead and wrote this. Rather small amount of code.

    September 20th, 2007 @ 06:40 PM

  3. Grant Rodgers
  4. Grant Rodgers
  5. Grant Rodgers
  6. Grant Rodgers
    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'"
    
    

    September 20th, 2007 @ 06:46 PM

  7. Grant Rodgers
    Grant Rodgers

    Not sure how add-ons are packaged, unfortunately - let me know if there's something else to be done.

    September 20th, 2007 @ 06:47 PM

  8. Chris Wanstrath
    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 ...>
    

    September 21st, 2007 @ 11:59 AM

  9. Chris Wanstrath
    Chris Wanstrath

    Maybe this is worth posting about.

    September 21st, 2007 @ 12:00 PM

  10. Grant Rodgers
    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.

    September 21st, 2007 @ 12:06 PM

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.