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).
There are two models:
1) users that stores all the users
2) my_friends that stores the friend list (that is reference table with M:M relation of user)
the structure of my_friends is following
…id……….user_id…………friend_id……..approved….
…10………20 ………………25……………….1……….
…10………21 ………………25……………….1……….
…10………22 ………………30……………….1……….
…10………25 ………………30……………….1……….
The Doctrine query to retrieve friend list id following
$friends = Doctrine_Query::create()->from('my_friends as mf')
->leftJoin('mf.users as friend')
->where("mf.user_id = 25")
->andWhere("mf.approved = 1");
Suppose I am viewing the user no.- 25.
With this query I am only getting the user no.- 30.
where as user no.- 25 is also approved friend of user no.- 20 and 21.
Please guide me, what should be the query to find all friend and is there any need to change the DB structure.
YAML
Member:
columns:
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
– Hello Amrit.
– I think you need to fetch data with two query. According to me you have to follow these steps