Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Cannot validates_associated of foreign_key object

#5740

Using rails 3 and ruby 1.9.2 p0 on win 7 x64.
When I use validates_associated with the following code and try to create a "Users Friend", I get the following error returned

NoMethodError (undefined method valid?' for 3:Fixnum):<br/> app/controllers/users_friends_controller.rb:46:inblock in create' app/controllers/users_friends_controller.rb:45:in create'

Code:
users_friend model:

class UsersFriend < ActiveRecord::Base
  belongs_to :user, :class_name => "User", :foreign_key => :requester
  belongs_to :user, :class_name => "User", :foreign_key => :requestee
  validates_associated       :requester, :requestee
end

user model:

class User < ActiveRecord::Base
  has_many :users_friends, :dependent => :destroy
  has_many :friends, :through => :users_friends
end

migration:

class CreatePlayersFriends < ActiveRecord::Migration
  def self.up
   create_table :users_friends do |t|
    t.integer :requester
    t.integer :requestee

    t.timestamps
   end

   create_table :users do |t|
    t.string :name

    t.timestamps
   end
  end

 def self.down
   drop_table :players_friends
 end
end

In the console:

user = User.new(:name => test).save
friend = UsersFriend.new(:requestee => 1, :requester => 1).save

Reported by Joey · September 30th, 2010 @ 04:36 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Joey
    Joey
    • Tag set to rails 3.0.0, foreign_key, validates_associated

    September 30th, 2010 @ 04:38 AM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Tag changed from rails 3.0.0, foreign_key, validates_associated to rails 300, foreign_key, validates_associated

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:59 PM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:59 PM