Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoid embeds_many with default order

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

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
like image 706
fl00r Avatar asked Aug 14 '11 13:08

fl00r


1 Answers

In mongoid 3.1.2 you can do something like this:

embeds_many :favorites, order: :title.desc

It also works with :title.asc

like image 116
luishurtado Avatar answered Oct 03 '22 06:10

luishurtado