Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase and query to store and retrieve friend list
    primarykey
    data
    text
    <p>I am developing a module in website to save and retrieve friend list. I am using Zend Framework and for DB handling I am using Doctrine(ORM). </p> <p>There are two models:</p> <p>1) <strong>users</strong> that stores all the users<br> 2) <strong>my_friends</strong> that stores the friend list (that is reference table with M:M relation of user)</p> <h2>the structure of <strong>my_friends</strong> is following</h2> <hr> <p>...id..........user_id............friend_id........approved....<br> ...10.........20 ..................25...................1..........<br> ...10.........21 ..................25...................1..........<br> ...10.........22 ..................30...................1..........<br> ...10.........25 ..................30...................1.......... </p> <hr> <p>The Doctrine <strong>query</strong> to retrieve friend list id following </p> <pre><code>$friends = Doctrine_Query::create()-&gt;from('my_friends as mf') -&gt;leftJoin('mf.users as friend') -&gt;where("mf.user_id = 25") -&gt;andWhere("mf.approved = 1"); </code></pre> <p>Suppose I am viewing the <strong>user no.- 25</strong>.<br> With this query I am only getting the <strong>user no.- 30</strong>.<br> where as <strong>user no.- 25</strong> is also approved friend of <strong>user no.- 20 and 21</strong>.<br> Please guide me, what should be the query to find all friend and is there any need to change the DB structure. </p> <p><strong>YAML</strong><br> Member:<br> columns: </p> <pre><code>id: primary: true type: integer notnull: true autoincrement: true userName: unique: true type: string(255) Address_id: type: integer(4) MemberPhoto_id: type: integer relations: address: class: Address local: Address_id foreign: id memberPhotos: class: MemberThumbnail foreignAlias: member local: MemberPhoto_id foreign: id refPeeps: columns: id: primary: true unique: true type: integer autoincrement: true Member_id: type: integer notnull: true Peep_id: type: integer notnull: true relations: Member: local: Member_id foreign: id Member: local: Peep_id foreign: id </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload