Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3782

order_by in embeds_many with multiples orders don't work

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None
    • None

      Example:
      School embeds_many :students

      In rails console:
      School.first.students.order_by(:name.asc, :email.desc)

      Works with name. but why ordering from second field (email) not work?? It's a bug?

      Conclusion:
      embeds_many don't order multiples fields and has_many can be depreciate in futures versions. Was a mistake includes mongo in my rails application??

      Any ideas?

      With has_many i don't have this problem, but reading stuff from mongoid documentation i saw this:
      Relational Associations
      Mongoid provides relational-style associations as a convenience for application developers who are used to dealing with relational databases, but we do not recommend you use these extensively.

      MongoDB provides no transactions, and no join support, so it is impossible to ensure that the database is kept in a consistent state with regards to referencing documents from one collection to another. Also, without support for joins, you will find that the number of database queries executed grows in order to retrieve documents with their associations, and can have a huge affect on performance since this is not where MongoDB's power lies.

      If you find that you have more relational associations in your application than embedded ones, it is recommended that you not use MongoDB and move to a relational database. Also, you will probably find this feature removed in future versions of Mongoid, in order to not allow developers to use the database in an incorrect fashion.

      Reference: http://mongoid.org/en/mongoid/docs/tips.html

            Assignee:
            Unassigned Unassigned
            Reporter:
            denoww denoww
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: