Actually, it depends on what you are going to do with your uncleared photos. If you want to display unsaved photos with the same action that you use to display the collection, then you will want to get this shared collection. Otherwise, I would leave it zero; I don’t like mixing “seed” data with user data in one table (what would you do with an “unconfirmed” collection) - it's too easy to accidentally erase your user data when you visit again.
Should there be a HABTM relationship? Again, it depends on how you want to use it. If you have a good chance that the photos will belong to several collections, go for it.
And what I saw was mentioned here that I wouldn’t do it: adding the attribute “ptype” to talk about single games from the collected photos (waste of database space - can you already get this information by calling photo.collection_id.nil? ); and using polymorphic models (you don’t want single-element photographs to behave completely different, I suppose that's why this added complexity for little use).
Named scopes, however, are a great idea and will be especially useful if you don't have a "uncollected" collection to find your singlets:
Or HABTM version:
named_scope :singletons, lambda { {:conditions => ['NOT EXISTS (SELECT * FROM collections_photos WHERE photo_id = ?)', self.id]} }
Hope this helps!
source share