This project is archived and is in readonly mode.

#5740 ✓stale
Joey

Cannot validates_associated of foreign_key object

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

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

Comments and changes to this ticket

  • Joey

    Joey September 30th, 2010 @ 04:38 AM

    • Tag set to rails 3.0.0, foreign_key, validates_associated
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:59 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:59 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages