Welcome Guest, Not a member yet? Register   Sign In
Datamapper many to many relationship
#1

[eluser]Noraj[/eluser]
Hi!

I'm using the Datamapper ORM (and that's great :o), but I'm facing an issue when managing a many to many relationship.
I've got a user table, and a role table. Each user can have several roles. Each roles is related to several users.
The problem is, I don't know how to retrieve the role from all users. I'm trying to develop an admin interface in which there's a table showing all the user main information : usename, email, status and role.

I tried this in my controller:

Code:
$users = new User();
$users->include_related('role', 'name')->get_iterated();
$this->load->view('admin/users/index',array('users' => $users));

And in my view :
Code:
<?php
      foreach($users as $u):
?>
...//other code to retrieve user information
<?php echo $u->role_name; ?>

When doing this, the result is a table where I actually see all my users. However, if a user has for example 3 roles, There's 3 rows showing his information, and each row has one of his role. For exemple, if the user has Test name and the roles of admin and customer, I end with this table :
Name Role
Test customer
Test admin

I don't understand... Maybe I don't do good in my controller, but I have no idea how to do it Sad
I'm sure this must be a simple issue, but I really can't understand what's going on... Sad

Any help would be really appreciated. ^o^
Thanks!


Messages In This Thread
Datamapper many to many relationship - by El Forum - 06-14-2013, 06:08 AM
Datamapper many to many relationship - by El Forum - 06-14-2013, 08:04 AM
Datamapper many to many relationship - by El Forum - 06-14-2013, 08:30 AM
Datamapper many to many relationship - by El Forum - 06-14-2013, 10:46 AM
Datamapper many to many relationship - by El Forum - 06-17-2013, 02:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB