ruby - Rails associating multiple :has_many -
i'm new rails , trying understand associating entities.
i have 3 entities right now: users, companies, , productlines.
company.rb:
class company < activerecord::base has_many :users has_many :productlines end
user.rb:
class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable belongs_to :company end
productline.rb:
class productline < activerecord::base belongs_to :company end
i've done migration scrips associate them, when click company on rails admin, i'm getting this:
sqlite3::sqlexception: no such column: productlines.company_id: select "productlines".* "productlines" "productlines"."company_id" = ? extracted source (around line #91):
# def prepare sql stmt = sqlite3::statement.new( self, sql ) return stmt unless block_given?
begin
edit: here migration:
class addproductlineidtocompanies < activerecord::migration def change add_column :companies, :productline_id, :integer add_index :companies, :productline_id end end
you should add company_id
productlines
, not product_line_id
companies
...
class addcompanyidtoproductlines < activerecord::migration def change add_column :productlines, :company_id, :integer end end
Comments
Post a Comment