开发者

rails assocation naming with table `ProductShow` and table `Product`

开发者 https://www.devze.com 2023-01-24 03:13 出处:网络
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)

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
0

精彩评论

暂无评论...
验证码 换一张
取 消