by eggsurplus

Control what your users can access and save time, money, and frustrations. Lock down sensitive data in SugarCRM or SuiteCRM to specific groups or teams. Supports unlimited assigned users, unlimited group assignments to records, custom layouts for each group, login/sudo capabilities and much more.

Free 30 day trial
Try it Now

#1660 - How to load M2M (many to many) relationship table columns data from beans

Closed General Question created by ramakantgangwar 3 years ago

Hi
currently I retreiving user bean
and then loading security group relationship
I want to use securitygroups_users tables fields
How to get those relationship table fields from bean?
current code :
$userBean = BeanFactory::getBean ( 'Users' );
$users = $userBean->get_list ( "users.date_modified DESC", "users.date_modified < '" . $dateTimeOffset . "'", 0, 10 );

foreach ( $users ['list'] as $user ) {

// load user security group if any

$user->load_relationship ( $rel_name );
$userAirlineGroups = $user->$rel_name->getBeans ();
**/****************I need here data of table securitygroups_users**********************/
**}

  1. eggsurplus member avatar

    eggsurplus Provider Affiliate

    3 years ago

    I'm assuming that the $rel_name is "SecurityGroups". I gave this a good try by looking through Sugar's code, but unfortunately you can only get the securitygroups table. The securitygroups_users table just isn't accessible with Sugar's framework. So the only way to do this is to do a direct SQL query and pass the user ID and the group ID. Make sure to also check for deleted = 0.

  2. ramakantgangwar member avatar

    ramakantgangwar

    3 years ago

    I am using now as following :

            $rel_name = $this->getLinkName ( $user->module_dir, 'SecurityGroups' );
            if ($rel_name) {
                $user->load_relationship ( $rel_name );
                $userSecurityGroups = $user->$rel_name->getBeans ();
    
                if (! empty ( $userSecurityGroups )) {
                    foreach ( $userSecurityGroups as $userSecurityGroupId => $userSecurityGroup ) {
                        //you can load any table 
                        $securityGroupUserRelationshipRows = $user->retrieve_relationships ( "securitygroups_users", array (
                                "securitygroup_id" => $userSecurityGroupId,
                                "user_id" => $user->id,
                                "noninheritable" => 0 
                        ), "{COLUMN_OF_SECURITYGROUP_USERS}" );
                                     }
                              }
                       }
    
    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      3 years ago

      Now I understand what you are trying to do. Nice work! This is great. I'm going to close this out for now, but feel free to follow up if needed.

This case is public. Please leave out any sensitive information such as URLs, passwords, etc.
Saving Comment Saving Comment...
Rating
Rating
  • "The perfect solution for managing security. Very stable and easy to implement. Must-have add-on for every CE implementation!"

    Read More Reviews

Keep up to date on the latest additions

We'll send you an email every month with handpicked add-ons, reviews, tricks and tips. Don't worry, we hate spam as much as you do.