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

belongs_to_related with different name from class name

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

      I have these models:
      class User
      include Mongoid::Document
      has_one_related :account, :foreign_key => :creator_id
      end

      class Account
      include Mongoid::Document
      belongs_to_related :creator, :class_name => "User", :foreign_key => :creator_id, :inverse_of => :account
      end

      When I try to do @user.account.build, it tries to @account.user = @user, when it should call @account.creator = @user instead.

      The culprit is in line 14-16 of mongoid/associations/has_one_related.rb

      @target = @klass.instantiate(attributes)
      name = @parent.class.to_s.underscore
      @target.send("#

      {name}

      =", @parent)

      It doesn't seem to respect the name of the belongs_to_related association.

            Assignee:
            Unassigned Unassigned
            Reporter:
            evansagge Evan Sagge
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: