Comments System with Social Networks Design

416 views Asked by At

Hi am making a simple Website with commenting System. User can login with social network ID (FB, Twitter et al) or register with the site and comment (there are user who will not wat to use their FB accounts for this). I have the two tables available (one for HybridAuth and another for local user table). Now my problem is how do I design the table and whole system to function that way? Basically my problem can be broken as follows: Comments table need ID of who is commenting (FK from either of the two but not both).

So what is the common approach (since many sites use disqus, FB, twitter et al for that) used?

If there is any link here at SO or elsewhere I will be glad to get pointed to.

1

There are 1 answers

4
Branko Dimitrijevic On BEST ANSWER

There are two approaches:

#1 Exclusive FKs

Have both FKs and a CHECK constraint on top of them, that makes sure one of them is NULL, as mentioned here.

Note that some DBMSes (most notably MySQL) don't enforce CHECK constraints, in which case you'll need to do that from triggers or client code.

#2 Inheritance

"Inherit" both kinds of users from a common table, then reference just the common table. Here is an example of how that can be done for "commentable" and "taggable" and "likable" content, similar principle can be applied to users.