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.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/9ce9767284046455d1f1df5955b8281d%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to