Rails: If Foo has_many :bars, do all :bars need to belong_to a Foo?

It depends on what you're going to do with your uncollected photos, really. If you want the ability to show the uncollected photos with the same action you use to show a collection, then you'll want to have that generic collection. Otherwise, I'd leave it nil; I don't like mixing "seed" data with user data in the same table (which you'd be doing with the "uncollected" collection) - it's too easy to accidentally wipe out your user data when reseeding Should it be a HABTM relationship?

Again, depends on how you want to use it. If there's a good chance you'll want photos to belong to multiple collections, go for it And the things that I've seen mentioned here that I would not do: Adding a 'ptype' attribute to tell singletons from collected photos (waste of DB space - you can already get that info by calling photo. Collection_id.

Nil? ); and using polymorphic models (you don't want singleton photos to behave drastically different, I assume, so this is added complexity for little to no benefit) Named scopes, though, are a great idea, and will be particularly useful if you don't have the "uncollected" collection to find your singletons by: Apologies for the Rails 2.3 code - it's what I know... named_scope :singletons, {:conditions => {:collection_id => nil}} Or the HABTM version: named_scope :singletons, lambda { {:conditions => 'NOT EXISTS (SELECT * FROM collections_photos WHERE photo_id =? )', self.Id} } Hope this helps!

It depends on what you're going to do with your uncollected photos, really. If you want the ability to show the uncollected photos with the same action you use to show a collection, then you'll want to have that generic collection. Otherwise, I'd leave it nil; I don't like mixing "seed" data with user data in the same table (which you'd be doing with the "uncollected" collection) - it's too easy to accidentally wipe out your user data when reseeding.

Should it be a HABTM relationship? Again, depends on how you want to use it. If there's a good chance you'll want photos to belong to multiple collections, go for it.

And the things that I've seen mentioned here that I would not do: Adding a 'ptype' attribute to tell singletons from collected photos (waste of DB space - you can already get that info by calling photo. Collection_id. Nil?); and using polymorphic models (you don't want singleton photos to behave drastically different, I assume, so this is added complexity for little to no benefit).

Named scopes, though, are a great idea, and will be particularly useful if you don't have the "uncollected" collection to find your singletons by: #Apologies for the Rails 2.3 code - it's what I know... named_scope :singletons, {:conditions => {:collection_id => nil}} Or the HABTM version: named_scope :singletons, lambda { {:conditions => 'NOT EXISTS (SELECT * FROM collections_photos WHERE photo_id =? )', self.Id} } Hope this helps!

That's very useful, thanks for the input! – Andrew Feb 23 at 4:35.

You could have photo. Ptype = 'collection' or photo. Ptype = 'single'.

This way you would be able to identify each photo by that type. Moreover, you can make it even more elegant by using a scope on the photos and specify collection_photos scope or single_photos. Another possibility is polymorphic models.

Have a photo model and a collectionPhoto and singlePhoto model that are using it.

So, I've never heard of ptype before. Is that just an attribute on the photo model, and I use it to tell if a photo is in a collection or not? – Andrew Feb 22 at 23:36 yes just a name :) You just can't use type because it's a Rails keyword; that's why I use ptype, but it can be anything you want.

– SpyrosP Feb 22 at 23:59.

I would only set the collection property when it belonged to a collection. Just be sure that your view code can handle this case.

Moreover, you can make it even more elegant by using a scope on the photos and specify collection_photos scope or single_photos. Another possibility is polymorphic models. Have a photo model and a collectionPhoto and singlePhoto model that are using it.

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