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

Relations in custom names :suggestion:

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.2
    • Affects Version/s: None
    • Component/s: None
    • None

      When you do has_many and belongs_to it creates a new property called tb_id and uses that to identify the relation.

      My issue is found in two cases I guess many can relate.

      MONGOID-4 You forgot to add has_many and belongs_to, or you didn't knew existed, and after a while when you added it all the custom relations you created don't automatically work or aren't recognized in the active record.

      MONGOID-5 consider the following clases Question User, a question has a user that asked it and a user that answered it, using has_many and belongs_to only, if I call User.Questions will only bring the questions he asked.

      My suggestion would be,

      has_many: questions, field: answered_by, name: answers

      That would allow me to get all the questions the user answered by doing User.answers instead of having to do
      Question.where(:answered_by => user[:_id])

      Sorry if I'm too n00b and this already is possible, but after centuries of research on the docs and forums I couldn't find how to do it.

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

              Created:
              Updated:
              Resolved: