8 months ago

decide how to extend a model

Posted 8 months ago by ederson

Hi all

I have a model called Category and another model let's say called SpecialCategory whichis just that a category with extra features.

Sometimes i need to get all Categories, sometime only SpecialCategories and sometimes the no SpecialCategories.

I having hard time determining the best way to structure this

It makes sense to have one table for both and extend Category but then i gets a bit confusing. If want all categories the SpecialCategories will appear in the resulting collection as Category so i will need a second db call

I thought about using a Trait and put the SpecialCategory logic there but it doesn't look right.

Or maybe just keep the SpecialCategory logic in the Category but that looks messy

Is there any alternative i haven't thought of ?

Please sign in or create an account to participate in this conversation.