You can add CommunityHub
model which will store 5 nullable id's like
food_id; car_id; electronics_id
and etc;
return that entities + preload cars/foods/electronics
In that case you can return values as
{
community_hub: {
id: 1,
food: { food_data },
car: nil
}
}
Hint: also you can add custom check to the db, which can provide consistence check with 1 foreign_key per record, so there are no multiple keys in one record.
Smth like
ALTER TABLE community_hubs ADD CONSTRAINT community_hub_fk_check_constraint
CHECK (
(
(mosque_id IS NOT NULL)::integer +
(house_id IS NOT NULL)::integer +
(food_id IS NOT NULL)::integer
) = 1
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…