ActiveRecord relations: Can A has_many Bs AND A has_one B at same time?

I think the cleanest implementation is having an extra FK in events for :key_photo.

I think the cleanest implementation is having an extra FK in events for :key_photo. # events. Rb belongs_to :key_photo, :class_name => 'Photo.

So, if I do this do I need to do the inverse somehow in photo. Rb - which, remember, already has belongs_to :post? I'm not that familiar with what ActiveRecord & ActivRelation do under the hood so don't want to create a confusing conflict.

– Meltemi Aug 26 at 16:12 I just updated my code - should be 'belongs_to' since events keep the foreign key... You don't need to add anything to photo. Rb; you just have to add key_photo_id to your events table. Then just use event.

Key_photo It doesn't really matter that there is already an association between photos and events - you can have as many as you need, as long as they use different foreign keys. – cmpolis Aug 26 at 16:44.

For what it's worth, I would add/use the one bit column. It makes your code more expressive and shows the intent of your code better. Relying on quirks like "oh, it has_one AND has_many" is going to confuse other developers, such as yourself, in the future.

You're writing for other developers first, not the compiler or the database. Come back after the fact and make it more beautiful/elegant, with profiling. The odds that this one bit are going to cause record storage problems are minimal, at best.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions