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.

This project is archived and is in readonly mode.

scope firings up on association

#6220

For example:

class Post < ActiveRecord
  belongs_to :user

  scope :published, where(:published => true)

  def self.some_action
    u = User.find(x)
    u.posts
  end

end

Post.published.some_action  # => SELECT "posts".* FROM "posts" WHERE "published" = "t" AND ("user_id" = "x");

Why there are we have scope for user association ? It should be isolated, isn't it?

Reported by eagle.anton (at gmail) · December 24th, 2010 @ 02:27 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. eagle.anton (at gmail)
    eagle.anton (at gmail)
    • Tag changed from scope association to association, rails3, scope

    December 24th, 2010 @ 02:41 PM

  2. Anil Wadghule
    Anil Wadghule

    Hi Eagle.

    What do you mean by not needing scope for user association. Can you please elaborate more?

    December 24th, 2010 @ 05:56 PM

  3. eagle.anton (at gmail)
    eagle.anton (at gmail)

    Problem was solved by AR#unscoped with block:

    def self.some_action
      u = User.find(x)
      unscoped { u.posts }
    end
    

    Ticket may be closed. Thank you.

    December 27th, 2010 @ 07:50 AM

  4. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to invalid
    • Importance changed from to Low

    January 2nd, 2011 @ 01:10 AM