hello. please give me some help on this quistion. I have a model named Discount. I also have three models which extend it including: ProductDiscount, VolumeDiscount, ShippingDiscount each one with its own table. the tables have but one column named discount_code.
now consider a situation the user can send a form which contains an input named discount_code
and the request is sent to DiscountController. discount model related to discount code may be in any of these tables or in none. what is the best and fastest way to find the specific discount in all these tables? thank you
Is there a special reason why you don't have just one "discounts" table that has a "type" column to differ between product / volume / shipping? Sounds very complicated to make sure you don't use the same discount code in multiple "types" otherwise.
I don't think there is a faster way than querying all tables one after the other - starting with the most probable first (so if you have mostly product discounts -> start there) and if you find it stopping querying the other tables.
I cant use only one discounts table because there are different types and in my opinion they cannot be Distinguished with a type column. for instance I may have product based discounts so there can be a one to many relation between this table and products. Or I may have shipping based discounts or volumn based discounts which may have some differences in table columns. that's why I have a Discount Model from which different types may be extended. then using polymorphism we can implement each model algorythm to affect ShoppingCart object.