This project is archived and is in readonly mode.

#6358 ✓stale

has_many :through join table conditions not applied on create

Reported by Ehren | February 1st, 2011 @ 07:44 PM

Rails 3.0.3

Given the following models

class User < ActiveRecord::Base
  has_many :roles
  has_many :owner_roles, :class_name => "Role", :conditions => {"" => "project_owner"}
  has_many :projects, :through => :roles
  has_many :owned_projects, :through => :owner_roles, :source => :project
class Role < ActiveRecord::Base
  belongs_to :user
  belongs_to :project
class Project < ActiveRecord::Base
  has_many :roles
  has_many :users, :through => :roles

When I attempt to use the owned_projects association to create a project for a user:


I get the error

ActiveRecord::UnknownAttributeError: unknown attribute:

The expected behavior is that the name attribute on the role record used to join the user to the new project would be set to "project_owner"

Comments and changes to this ticket

  • Ehren

    Ehren February 1st, 2011 @ 07:54 PM

    • Tag changed from 3.0.3, has_many, has_many_through_association, hmt to 3.0.3, bug, bugs, has_many, has_many_through_association, hmt
  • andrehjr (at gmail)

    andrehjr (at gmail) February 3rd, 2011 @ 12:49 AM

    try this:

     has_many :owner_roles, :class_name => "Role", :conditions => { :name => "project_owner" }
  • rails

    rails May 3rd, 2011 @ 01:00 AM

    • State changed from “new” to “open”
    • Tag changed from 3.0.3, bug, bugs, has_many, has_many_through_association, hmt to 303, bug, bugs, has_many, has_many_through_association, hmt

    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.

  • rails

    rails May 3rd, 2011 @ 01:00 AM

    • 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=""></a>

People watching this ticket