1

I have 3 tables.

  • People
  • Post
  • Likes

When I design ER it has Circular Reference(cyclic dependency)..

 1:N

People --------< Post

 1:N

Post ----------< Likes

 1:M

People --------< Likes

Logic is

  • 1 people can have many posts.
  • 1 post has many likes.
  • 1 people can like many posts (created person cannot like his own post).

How can i remove this kind of cyclic design?? or my db design is wrong??

any suggestion.. thanks advance

Ragu
  • 373
  • 5
  • 15
  • 1
    I'm not sure what you mean, I don't see a circular reference. – Rabbit Dec 17 '15 at 17:56
  • people post and likes three are inter connected ?? is it no circular reference – Ragu Dec 17 '15 at 17:58
  • 1
    No, not necessarily. You would need to post the actual data structure. – Rabbit Dec 17 '15 at 18:03
  • Also, your third relationship is incorrect. It's 1:N, not N:M. – Rabbit Dec 17 '15 at 18:06
  • different tables in MySQL. they have some attribute and each of them has id(integer value) as primary key – Ragu Dec 17 '15 at 18:06
  • i corrected third relationship. – Ragu Dec 17 '15 at 18:07
  • 1
    You need to post the actual DDL. But if your structure is like the one @bcampolo posted below, then it's not a circular reference. See the answer in this thread: http://stackoverflow.com/questions/14999131/avoid-circular-dependency – Rabbit Dec 17 '15 at 18:10

1 Answers1

3

I'm not sure which part is cyclical in your example, but the design I first thought of was this:

People
Column1: Person ID
Column2: Name

Post
Column1: Post ID
Column2: Person ID who posted

Likes
Column1: Like ID
Column2: Post ID that was liked
Column3: Person ID that liked the Post

bcampolo
  • 593
  • 5
  • 12
  • 1
    i design like this, but i thought likes table has circular reference..i am not sure about that..when i get person from like table through post .it will load infinite data?? – Ragu Dec 17 '15 at 18:11
  • Nope. No infinite data. Whatever answer you're trying to obtain through your query, you can do without a circular reference. – Rabbit Dec 17 '15 at 18:34
  • 1
    While this is a good design, I see little purpose for the LikeId field in the likes table. – Dan Bracuk Dec 17 '15 at 18:53
  • @Dan Bracuk - true, it is not needed, but provides a primary key that may later be used as the FK in another table or as a resource identifier in a RESTful service. – bcampolo Dec 17 '15 at 19:42