Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM Relating Models with extra join and where
  • In much of the work I do I need to have advanced permissions telling if a person can read or write certain bits of content. I tend to do this using permission_sets and permission_masks. A piece of content can be defined to a specific permission_set which then knows what a person can do with it depending on what permission_mask they're wearing. So I would have various tables looking something like this: permission_sets
    permission_set_id
    permission_set_name permission_masks
    permission_mask_id
    permission_mask_name permissions
    permission_mask_id
    permission_set_id
    permission_show
    permission_read
    permission_create
    permission_moderate topics
    topic_id
    topic_title
    topic_forum_id
    topic_permission_set_id forums
    forum_id
    forum_title users
    user_id
    user_name
    user_permission_mask_id What I tend to do now is something like this:
    $user = func_to_get_logged_in_user();
    
    $forum_id = uri::segment(3);
    
    $forum = 'SELECT * FROM forums WHERE forum_id = '.$forum_id;
    
    //Edited to fix the formatting, there's no wrap on code tags here......
    $topics = 'SELECT topics.* 
    FROM topics
    INNER JOIN permissions
    ON topics.topic_permission_set_id = permissions.permission_set_id
    WHERE permissions.permission_mask_id = '.$user->user_permission_mask_id.'
    AND permissions_permission_show = 1
    AND topics.topic_forum_id = '.$forum_id;
    
    func_to_show_page('forum', array('forum'=>$forum,'topics'=>$topics));
    

    What i'd like to be able to do is something like this (adapted from an example in the docs)
    $forum = Model_Forum::find($forum_id);
    
    $topics = $forum->topics;
    

    Without the extra permissions checks the docs suggest it would be done as simply as:
    $_has_many = array('topics' => array(
        'model_to' => 'Model_Topics',
        'key_from' => 'forum_id',
        'key_to' => 'topic_forum_id'
    ));
    

    But this doesn't look like it gives me the options for additional permission checks. Is there any way to add this sort of functionality? The Permissions check would be done every single time, even when the user isn't logged in since there is a default permission_mask for guests as well. So it should be basically impossible for me to do anything with the topics table without joining the permissions table.
  • Just added to dev branch and examples in docs.
  • On where/order_by statements for relations: http://dev.fuelphp.com/issues/91 It's planned for 1.1, maybe earlier in the develop branch. EDIT: referenced the wrong issue before.
  • Cheers for the reply, I suppose its a waiting game then.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion