开发者

Mongoid embeds_many with default order

开发者 https://www.devze.com 2023-03-27 19:57 出处:网络
How can I set default order to my embeded objects, like: 开发者_如何学C class Post embeds_many :comments, :order => \"author\"

How can I set default order to my embeded objects, like:

开发者_如何学C
class Post
  embeds_many :comments, :order => "author"
  accepts_nested_attributes_for
end

Now I handle it with passing order straight:

f.fields_for :comments, @post.comments.asc(:author) do |comment|
  ...
end


In mongoid 3.1.2 you can do something like this:

embeds_many :favorites, order: :title.desc

It also works with :title.asc

0

精彩评论

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