I am trying to figure how to create a "repository" file (for the symfony2 users) where i will put all my special behaviour queries.
I have a simple db shema with :
- User (email)
- RelationType (name)
- UserXUserXRelation (fromUser, toUser, relation)
I want to retrieve the user with relation X on my user Y, so in sql it will looks like :
var sql = 'SELECT u.email, u.id
FROM user u
INNER JOIN UserXUser uxu ON uxu.toUser_id = u.id
WHERE uxu.relation_id = 1 AND uxu.fromUser_id = '+id
Where should i create this method ? I tried in the db/shema.js and app/models/user.js without success. I found here Using arbitrary mySQL Query with JugglingDB? that i should use the shema object to use "query", where and how could I use it ?
Does the callback will look like this :
function(err, data) {...}
Is there some best practice about code separation in that case ?
Additional question : is there a way to bind parameters the PHP PDO way with jugglingdb ?
Thanks for all.