Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:16:58+00:00 2026-06-06T06:16:58+00:00

I have just created a new project with a many-to-many relation (User-Group) and the

  • 0

I have just created a new project with a many-to-many relation (User-Group) and the code below.

As you can guess in the code I’m trying to assign manually groups to a user, but it doesn’t assign it anything…any idea?

User:
  columns:
    id: 
      type: integer(4)
      autoincrement: true
      primary: true
    username:
      type: string(255)
    password:
      type: string(255)
  attributes:
    export: all 
    validate: true

Group:
  tableName: group_table
  columns:
    id: 
      type: integer(4)
      autoincrement: true
      primary: true
    name:
      type: string(255)
  relations:
    Users:
      foreignAlias: Groups
      class: User
      refClass: GroupUser

GroupUser:
  columns:
    group_id:
      type: integer(4)
      primary: true
    user_id:
      type: integer(4)
      primary: true
  relations:
    Group:
      foreignAlias: GroupUsers
    User:
      foreignAlias: GroupUsers

The code is this:

  public function executeIndex(sfWebRequest $request)
  {
    $user = Doctrine_Core::getTable('User')->find(1);

    $groups = Doctrine_Core::getTable('Group')->findAll();

    $user->setGroups($groups);

    $user->save();
    $this->forward('default', 'module');
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:16:58+00:00Added an answer on June 6, 2026 at 6:16 am

    Try defining the relation in the User entity too (and don’t using foreingAlias in Groups). Also use the local and foreign fields.
    So, schema.yml should look like:

    User:
      ...
      relations:
        Groups:
          class: Group
          refClass: GroupUser
          local: user_id
          foreign: group_id
    
    Group:
      ...
      relations:
        Users:
          class: User
          refClass: GroupUser
          local: group_id 
          foreign: user_id
    

    If that doesn’t work, I think you can set the groups with the Doctrine “link” method.
    See Record.php (probably in lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine folder)

    Example:

    $groups_ids = array();
    foreach($groups as $group) $groups_ids[] = $group->getId();
    $user->link('Groups',$groups_ids);
    

    Also, if you are trying only to add instances to that relation (and you hate the person who will fix your code in the future) you can create N-GroupUsers
    Example:

    foreach($groups as $group) {
        $ug = new GroupUser();
        $ug->setUserId($user->getId());
        $ug->setGroupId($user->getId());
        $ug->save();
    }
    

    Please, use the first option and let me know if any of this works for you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just created a new project in VS2010 using the Visual c# >
I have a table that we just enabled FileStreams on. We created a new
i have just created a drum app. The user taps on the individual buttons
I have created a Project having many activities. One activity is to record the
I have just created this table: create table dbo.OrderTypes ( ID smallint primary key
I have just created an HTML5 page with a background image in the top
I have just created a report in Report Manager using a Stored Procedure which
I have just created a GIT on a folder. I now want to add
I have just created 2 pointers which has undefined behavior and try to invoke
I have just created my first Rightscale ServerTemplate and Deployment using a bunch of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.