rails assocation naming with table `ProductShow` and table `Product`
i'm confused about assocation table naming (for many to many asscoation)
now i have a model n开发者_如何学JAVAamed ProductShow (in db it named product_shows)
also another model named Product (in db it named products)
now i want make a assocation table between them
this relationship between is
Product
has_and_belongs_to_many :product_shows
ProductShow
has_and_belongs_to_many :products
what's the name for this assocation table?
also is there some way or tool can check this?
I usually prefer to implement this using bi-directional has_many
association.
class Product
has_many :product_product_shows
has_many :product_shows, :through => :product_product_shows
end
# table product_product_shows
# product_id
# product_show_id
class ProductProductShow
belongs_to :product_show
belongs_to :product
end
class ProductShow
has_many :product_product_shows
has_many :products, :through => :product_product_shows
end
精彩评论