I'm fairly new to the rails world and I've been tasked with making an online store.
However I am currently having trouble setting up the database relationships. I have product, dimension and shipping classes. A product can have several dimensions, depending on what product variant the customer chooses. The dimensions of the product can dictate how much the shipping will cost, however there will also be several shipping options on offer per dimensions. Here is my current setup:
Product.rb
class Product < ActiveRecord::Base
attr_accessible :title, :description, :image_url, :price, :category_id, :weighting, :stock
has_many :dimensions
end
Dimensions.rb
class Weight < ActiveRecord::Base
attr_accessible :product_id, :size, :weight
has_and_belongs_to :shippings
belongs_to :product
end
Shipping.rb
class Shipping < ActiveRecord::Base
attr_accessible :description, :insurance, :name, :price, :size_id, :weight_id
has_and_belongs_to :dimensions
end
Could anyone give me some advice as to whether this is the best way to setup this database relation? And if not, what would be a more optimum solution?
I've been told to utilise has_many :through, however I'm not sure how best to implement this.
Thanks