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 9001453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:26:18+00:00 2026-06-16T00:26:18+00:00

I have a one to many relationship between accounts and users. I am using

  • 0

I have a one to many relationship between accounts and users. I am using sonata admin for CRUD. As I know, it uses Symfony forms to get the job done. I tried to add a field like this:

        ->add('users', 'entity', array(
            'class'    => 'AcmeDemoBundle:User',
            'required' => true,
            'multiple' => true,
            'expanded' => true
        ));

I also tried with sonata_type_model

        ->add('users', 'sonata_type_model', array(
            'class'    => 'AcmeDemoBundle:User',
            'required' => true,
            'multiple' => true,
            'expanded' => true
        ));

The issue is that nothing (related to the relationship) gets saved when the account is edited (when I edit a user everything gets updated). I know that I have to update the owning side (user side) but I did not succeed doing that because “public function addUser($user)” is not called so I can not add something like “$user->setAccount($this)” to that function.

My entities look like this:

class Account
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string")
 */
protected $name;

/**
 * @ORM\OneToMany(targetEntity="Acme\DemoBundle\User", mappedBy="account", cascade={"persist", "remove"})
 */
protected $users;

/**
 * Add users
 *
 * @param Acme\DemoBundle\Entity\User $user
 * @return Account
 */
public function addUser(\Acme\DemoBundle\Entity\User $user)
{
    $user->setAccount($this);
    $this->users[] = $user;

    return $this;
}

/**
 * Remove users
 *
 * @param Acme\DemoBundle\Entity\User $user
 */
public function removeUser(\Acme\DemoBundle\Entity\User $user)
{
    $user->setAccount(null);
    $this->users->removeElement($user);
}

/**
 * Get users
 *
 * @return Doctrine\Common\Collections\Collection 
 */
public function getUsers()
{
    return $this->users;
}
}

.

class User extends BaseUser
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\ManyToOne(targetEntity="Acme\DemoBundle\Account", inversedBy="users")
 */
protected $account;

/**
 * Set account
 *
 * @param Acme\DemoBundle\Entity\Account $account
 * @return User
 */
public function setAccount(\Acme\DemoBundle\Entity\Account $account = null)
{
    $this->account = $account;

    return $this;
}

/**
 * Get account
 *
 * @return Acme\DemoBundle\Entity\Account 
 */
public function getAccount()
{
    return $this->account;
}
}
  • 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-16T00:26:19+00:00Added an answer on June 16, 2026 at 12:26 am

    My issue was related to this https://github.com/symfony/symfony/issues/1540

    After I added by_reference => false Account setters are called and the owning side can be updated.

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

Sidebar

Related Questions

I have a one to many relationship between Admins and Users. Admin has_many :users
I'm using Entity Framework 4 and have a one-to-many relationship between a parent and
I am using nHibernate for db persistence. I have a one-to-many relationship defined between
Let's say you have a one-to-many relationship between Users and Orders (where one user
I have one-to-many relationship between parent and child Java objects. The parent object uses
I have a one-to-many relationship between two classes for this situation. I have a
I have a one-to-many relationship between Foo and Bar and I cannot perform an
android noob... I have two tables, with a one to many relationship between country_tbl
I have a Hash Map (many-to-one relationship between texts and boolean values): name flag
I have a one-to-many relationship between Part and Params (a Part has many Params).

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.