What are the pros and cons of breaking out optional 1:1 attributes into their own separate model.
For example, I just encountered Rails code like this:
class Dogs << ActiveRecord::Base
# :id (pk), :breed, :weight, :height, :tail_length
end
class DogSpotsInfo << ActiveRecord::Base
# :dog_id (pk), :spot_color, :avg_spot_size, :num_spots
end
But this is how I would have done it (leaving the spot fields null as necessary):
class Dogs << ActiveRecord::Base
# :id, :breed, :weight, :height, :tail_length, :spot_color, :avg_spot_size, :num_spots
end
At the DB level, I believe the only difference is queries involving the optional attributes will require another join?
Are there any other cons to the former approach? Are there any pros?
EDIT:
I guess on a massive dogs table where say 20% of dogs have spots, maybe one pro the former approach is faster sequential scans but I'm not 100% sure about that, and if that's the only pro it seems like premature optimization.
Another pro I can think of is it keeps the models smaller and neater. But if that is the goal, perhaps could you do it without affecting the DB structure, by having something like has_spots :spot ? What is the best practice here?