Jason,
thanks for your answer. The link you provided was useful.
> In general if you have a "do" you need an "end",
It does have an end, I left it out of the reply because it is in the
first post. The complete statement I'd like to have would be:
has_many :children, -> { order 'id asc' }, dependent: :destroy do
def persisted
collect { |a| a if a.persisted? }
end
end
What I'm trying to do is briefly mentioned in the page you referenced
(
http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many#461-User-a-block-to-extend-your-associations)
but there is no link to further documentation or examples. I just would
need to add the scope to the example, from:
has_many :children, :dependent => :destroy do
def at(time)
proxy_owner.children.find_with_deleted :all, :conditions => [
"created_at <= :time AND (deleted_at > :time OR deleted_at IS
NULL)", { :time => time }
]
end
end
to
has_many :children, -> { order "posted_on" }, :dependent => :destroy do
(rest of the code)
but this is not covered in THAiSi's note. I think this is very useful,
and should be easier to find documentation.
Regards.