Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from deJaVisions/gist:1906315
Created February 25, 2012 03:59
Show Gist options
  • Select an option

  • Save radar/1906350 to your computer and use it in GitHub Desktop.

Select an option

Save radar/1906350 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
has_many :products_materials
has_many :materials, :through => :products_materials
end
class Material < ActiveRecord::Base
has_many :products_materials
has_many :products, :through => :products_materials
end
class ProductsMaterial < ActiveRecord::Base
belongs_to :product
belongs_to :material
end
@deJaVisions

Copy link
Copy Markdown

well i tried copying your above example line for liine but kept getting:

1.9.3-p0 :020 > p = Product.first
Product Load (28.6ms) SELECT "products".* FROM "products" LIMIT 1
=> #<Product id: 1, title: "teddy", created_at: "2012-02-25 04:28:14", updated_at: "2012-02-25 04:28:14">
1.9.3-p0 :021 > p.materials
NameError: uninitialized constant Product::ProductsMaterial

hmm, must be something simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment