Hi Jeremy et al,

Just had a chance to try out unionising those two comments tables, however, 
I notice that in creating the union the comment id's become redundant as 
e.g. {id: 1} exists for both the `photo_comment` and the `photoset_comment` 
tables. Is there a trick to creating mutually unique keys for tables in 
union?

Not too far into it, my query is also insufficient..

```
PhotoSetComment.where(:photoset_id => sid)
    .union(PhotoComment.where(:photo_id => pid))
```

Whereas I actually need comments for each `Photo.where(:photoset_id => 
sid)`. Should I chain unions to do this, or does Ruby have some nice syntax 
to enumerate each Photo into a union?

Thanks,

Adam

On Thursday, 22 August 2013 16:22:00 UTC+1, Adam Gamble wrote:
>
> Many thanks :)
>
> On Thursday, 22 August 2013 16:09:44 UTC+1, Jeremy Evans wrote:
>>
>> On Thursday, August 22, 2013 2:49:59 AM UTC-7, Adam Gamble wrote:
>>>
>>> Thanks Jeremy– Unions may be a good call, equally it'd be nice to have 
>>> just one 'Comment' table.. so to explain my situation I have a table 
>>> 'PhotoSet' and a 'Photo' table.. a user should be able to comment on a Set, 
>>> or a Photo –but for the purposes of the application the two should be 
>>> aggregated in a feed.
>>>
>>> As Photo's are many-to-one with the PhotoSet. I could have comments just 
>>> linked to the PhotoSet, where a comment *can* reference a Photo, 
>>> otherwise it becomes a general comment on the set.. make sense?
>>>
>>
>> I personally think you would be better off with both photo_comments and 
>> photoset_comments tables.  You don't want a foreign_key in your photoset 
>> table referencing the comments table, since that lets you only have a 
>> single comment per photoset.  Instead, the photo_comments table would have 
>> a foreign key referencing photos, and the photoset_comments table would 
>> have a foreign key referencing photosets.  This allows you to have multiple 
>> comments per photo and per photoset.
>>
>> Thanks,
>> Jeremy
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to