[eluser]coldKingdom[/eluser]
Hi, and thank you for a wonderful library!
I have a table like this
friends_users
id - unique ID
user_id - relates to usertable
friend_id - relates to usertable
relationship_id - relates to relationship status table
approved
It's the
relationship_id I have little bit of a problem with as it should relate to a table like
relationships
id - unique ID
title - What type of relationship. Friend etc.
So in my code I have
User-model
Code:
<?php
class User extends DataMapper {
var $has_many = array(
"news",
"image",
"friend" => array(
'class' => 'user',
'other_field' => 'user',
),
'user' => array(
'other_field' => 'friend'
)
);
User-controller
Code:
//Create user objects
$users = new User();
$users->select("id, first_name, last_name, presentation, picture");
$users->where("id", $id);
//Get the user
$users->get(1);
//If the ID does not exist
if (!$users->exists())
show_404();
//Get the users friends
$users->friend->select('id, first_name, last_name');
$users->friend->where('approved', '1');
$users->friend->get();
I probably should do a
$users->friend->where_join_field/include_related or something like that, but it only relates to the user and it's driving me nuts as it should get the title of the relationship
Can anyone put me in the right direction? All help is highly appreciated.
Thank you!