ruby - Rails Join Table with Model Assoc -


i have model relies on associations of 2 other models so:

class inventoryitem < activerecord::base   attr_accessible :vendor_id, :price, :upc   has_many :items   belongs_to :vendor end 

my question this: if have these associations in join model, need specify these associations again in migration create inventory_items table in includes attributes :items , :vendor? here current migration (hasn't run yet) create table:

class createinventoryitems < activerecord::migration   def change     create_table :inventory_items |t|       t.integer :upc       t.decimal :price       t.integer :vendor_id     end   end end 

browsing sqlit3 db leads me believe need somehow. best way that? i'm newish ror, feedback welcome , appreciated.

your models need know associations, migrations don't care associations. long have foreign keys in child model, that's need in migration set associations on database level.

with rails, idea little possible on database level, , as possible on application (orm) level. therefore, let models know associations, enable them use according orm methods handle associations, database doesn't need know associations.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -