开发者

How do I make an ActiveRecord scope that doesn't affect the query in Rails 3 using Arel (presumably)?

开发者 https://www.devze.com 2023-04-03 02:49 出处:网络
Essentially I am looking for a no-op type of relation to apply to a chain of scopes. Lets say I have a chain of scopes:

Essentially I am looking for a no-op type of relation to apply to a chain of scopes.

Lets say I have a chain of scopes:

Post.approved.published.all

Now, for debugging purposes, I wish to make the published scope do nothing at all, so that the chain will only return approved posts, regardless of whether they are 开发者_高级运维published or not.

What would I return in the following method:

def self.published
  # what to return?
end


Make published an alias for all, or use scoped to return a relation to which additional conditions can be chainged:

def self.published
  all
  #or
  scoped
end

I would use a scope, returning all...

scope :published, all

or, make it an alias for scoped:

scope :published, scoped
0

精彩评论

暂无评论...
验证码 换一张
取 消