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

Problem with relations pointing the same model

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

      I have this model:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class Match
        include Mongoid::Document
        include Mongoid::Timestamps
        field :user1_id, :type => BSON::ObjectId
        field :user2_id, :type => BSON::ObjectId
      
        belongs_to :user1, :class_name => "User", :foreign_key => "user1_id"
        belongs_to :user2, :class_name => "User", :foreign_key => "user2_id"
      end
      

      `

      And User model like this:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      class User
        include Mongoid::Document
        include Mongoid::Timestamps
      
        has_many :hosted_matches, :class_name => "Match", :foreign_key => "user1"
        has_many :invited_matches, :class_name => "Match", :foreign_key => "user2"
      end
      

      `

      All cool, but when doing this:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      @match=Match.new
      @match.user1 = @user1
      @match.user2 = @user2
      @match.save!
      

      `

      After saving, user1 and user2 will point to the same user...

      The only way I got this running properly is by setting ids:

      Unable to find source-code formatter for language: `. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      @match=Match.new
      @match.user1_id = @user1.id
      @match.user2_id = @user2.id
      @match.save!
      

      `

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

              Created:
              Updated:
              Resolved: