Welcome Guest, Not a member yet? Register   Sign In
Helt me with associations
#1

[eluser]Carmichael[/eluser]
I've three tables. Users, groups, permissions and permissions_map.

Users
Code:
id|username|group_id

Groups
Code:
id|name

Permissions
Code:
id|permission

Permissions_map
Code:
group_id|permission_id

So... in the Permissions table I list all the permissions there is. In the Permissions_map table I list all permissions a group has.

For example... it can look like this in Permissions map
Code:
group_id|permission_id
   1    |      1
   1    |      2

And like this in Permissions
Code:
id|permission
1 |edit_user
2 |remove_user

I wan't to be able to get the permission name from permissions by the permission id in permissions map.

Code:
class User extends ActiveRecord\Model
{

    static $table = "users";
    
    static $belongs_to = array(
        array('group')
    );

class Group extends ActiveRecord\Model
{

    static $table = "groups";
    
    static $has_many = array(
        array('users'),
        array('permissions')
    );

class Permission extends ActiveRecord\Model
{

    static $table = "permissions_map";
    
    static $belongs_to = array(
        array('group')
    );

I can get all the permissions a group has in permissions_map, but I wan't to get the permission name by the ids too from permissions. How do I do that?
#2

[eluser]Aken[/eluser]
Considering this is an ActiveRecord ORM question rather than one relating to CodeIgniter itself, I would check their docs: http://www.phpactiverecord.org/projects/...sociations
#3

[eluser]Carmichael[/eluser]
[quote author="Aken" date="1343694963"]Considering this is an ActiveRecord ORM question rather than one relating to CodeIgniter itself, I would check their docs: http://www.phpactiverecord.org/projects/...sociations[/quote]
You're right. Just one question about the ORM. Can you access tables by joining them in a model or do have to create a model for each table to access data from the table?
#4

[eluser]Aken[/eluser]
I don't know, personally - never used it. Check out their docs and forums, I'm sure you can find the answer.




Theme © iAndrew 2016 - Forum software by © MyBB