SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Scenario #1 facebook add friend

    Hi ,

    I'm using MySql Hibernate , and I have a theory question

    scenario : A sends friend request to B => B approve => QUESTION

    Question : Now in the databse I need A to be B friends and B to be A friend ,

    In code , when A adds B to his friends list ,

    Code:
    A.addfriend(B) and then session.save()
    does the databse should also add A to B friend automatically?

    or addintilnal additional code is needed for B add A as friend ?

    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,269
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    depends on whether you are storing the friendship in two rows or in only one
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you explain what you mean 1 or 2 rows?
    Doesn't your depend , depends on my answer for my question ? It can be changes regarding the 'right way'

    As it is now , it doesn't save automatically and the table is :

    user_user

    user_id ------ friend_id
    Aid------------- Bid
    Aid -------------Xid

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,269
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    storing the relationship in one row means this --

    user_id ------ friend_id
    Aid------------- Bid

    storing the relationship in two rows means this --

    user_id ------ friend_id
    Aid------------- Bid
    Bid------------- Aid

    both of those approaches work fine

    for only one row, if you want to find somebody's friends, you have to look for that person in both columns

    for two rows, if you want to find somebody's friends, you would look for that person in only the user_id column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't see how one row helps , because with one row I can only do
    Code:
    A.getFriends();
    which will get me B , but if I do
    Code:
    B.getFriends();
    , it will be empty .

    I can't see cleary how one/two rows help answer , although
    the two rows seems what I want and need , for both methods from to work will non empty results.

    thanks again for your time

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,269
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    if you want to store two rows for the friendship, then you must do so

    and no, to answer your question, the database cannot add the second row automatically

    you have to do it with code
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •