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

Custom keys for associations MONGOID-1851

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

      Relations now have one more option,

       
      Given those models
      

      ruby
      class Person
      include Mongoid::Document

      field :username
      has_many :cats, primary_key: :username
      end

      
      

      ruby
      class Cat
      include Mongoid::Document

      field :name
      belongs_to :person, primary_key: :username
      end

      
      

      ruby
      crazy_lady = Person.create!
      20.times

      { crazy_lady.cats.create! }

       
      this will create 20 cats, and the fk, on Cat, 

      person_id{{`}}, will be the username.

        Attachments

          Activity

            People

            Assignee:
            durran Durran Jordan
            Reporter:
            arthurnn Arthur Nogueira Neves
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: