I am designing a database with the code igniter datamapper.
Imagine that I have a three tables one with users and one with friends and one with foods friend like. I am trying to access the food friend like. I have populated all the tables with data mapper.
Here is how I do it:
user table has id, user_name, gender, user_id fields.
Every user has many friends and friend table is:
friend table has id, friend_id, friend_name, user_id
Every friend has many foods and here is table for it:
friend id food
I was able to populate the tables by filing out the values. Lets say for example:
user:
1 andy male 394
2 jen female 439
..
friend:
1 243 mark 394
2 493 silvia 394
3 459 gloria 439
...
So when I try to access friend of a user from the database I do this:
$u->get_by_user_id($data['user']['id']);
if ($u->exists())
{
$data['user']['first_name'] = $u->first_name;
$data['user']['last_name'] = $u->last_name;
$data['user']['gender'] = $u->gender;
$data['user_friends']=$u->friend->get();
and it works…(i don’t know why it knows what is the id of friend to relate to) but it works…
now I am trying to go one level deeper and access or get() every users’ friends foods…but I do’t know how?
Ok I found the answer: