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

By clicking you consent to share your profile with the developer

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

Closed General Question created by so_removed_7 7 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

    7 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. so_removed_7 member avatar


    7 years ago

    I am using now as following :

            $rel_name = $this->getLinkName ( $user->module_dir, &#039;SecurityGroups&#039; );
            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

      7 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...
  • "This impressive add on is easy to use, extremely flexible, and huge time saver. This add on exceeded our expectations and is worth every penny!"

    Read More Reviews