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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:09:43+00:00 2026-05-31T03:09:43+00:00

I have two entities Room.php /** * @ORM\Table(name=room) * @ORM\Entity(repositoryClass=Ahsio\StackBundle\Repository\RoomRepository) */ class Room {

  • 0

I have two entities

Room.php

/**
 * @ORM\Table(name="room")
 * @ORM\Entity(repositoryClass="Ahsio\StackBundle\Repository\RoomRepository")
 */
class Room
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
     protected $id;

     // ...    

    /**
     * @ORM\OneToMany(targetEntity="Ahsio\StackBundle\Entity\Workstation", mappedBy="room", cascade={"persist", "remove"}, orphanRemoval=true)
     */
     protected $workstations;

and workstation.php

/**
 * @ORM\Table(name="workstation")
 * @ORM\Entity(repositoryClass="Ahsio\StackBundle\Repository\Workstation")
 */
 class Workstation
 {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
     private $id;

    /**
     * @ORM\ManyToOne(targetEntity="Ahsio\StackBundle\Entity\Room")
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id", nullable=false)
     */
     private $room;

     // ...

I added a Room Type with a collection field for adding/updating/removing workstations

RoomType.php

class RoomType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('id', 'hidden', array(
                'read_only' => true,
            ))
            // ....
            ->add('workstations', 'collection', array(
                 'type'         => new WorkstationType(),
                 'allow_add'    => true,
                 'allow_delete' => true,
                 'by_reference' => false,
            ))
        ;
     }
     // ...
}

The Workstation Type is a simple one with only two fields (id & number).

The problem is that when I’m trying to bind RoomType for an existing Room (which contains two workstations of id (1 and 2)) with The following array (Which contains only one of the two workstations):

array(4) {
  ["id"]=> string(1) "3"
  ["workstations"]=> array(1) {
    [0]=> array(2) {
      ["id"]=> int(1)
      ["number"]=> int(200)
     }
  }

The update is well done, The workstation for id=2 is removed. But when I’m trying to remove all workstations for a given Room using:

array(4) {
  ["id"]=> string(1) "3"
  ["workstations"]=> array(0) {
  }

The workstations are still there, The bind I did is well performed, here is what I got when I did a $form->getData() after binding my $form using the last given array:

object(Ahsio\StackBundle\Entity\Room)#229 (4) {
    ["id":protected]=> string(1) "3"
    ["name":protected]=> string(20) "first room (updated)"
    ["description":protected]=> string(39) "This first room is an old one (updated)"
    ["workstations":protected]=> array(0) {
    }
 }

So, no workstations for the updated Room. Can someone tell me why my workstations aren’t deleted when I persist this last binded Room?

Here is a part of my Controller code which I’m using to test the update …

        // The Room $id is given ... 
        $roomArray = array(
        'id'           => $id, 
        'name'         => 'first room (updated)',
        'description'  => 'This first room is an old one (updated)',
            'workstations' => array(),
        );
        $form     = $this->createForm(new RoomType(), $room);      

        $form->bind($roomArray);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($room);
            $em->flush();
        }
  • 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-05-31T03:09:44+00:00Added an answer on May 31, 2026 at 3:09 am

    I think the setter that receives workstations array is never called because the array is empty.

    Try to see if it is called by adding a trace.

    Also, you should add the cascade=”merge” option in your workstations mapping.

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

Sidebar

Related Questions

I have two entities: Event and Comment. @Entity @Table(name = events) public class Event
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities @Entity public class Tabulka{ @OneToMany(mappedBy = tabulka) private List<VysledkyHraca> vysledkyHraca;
I have two entities with many-to-many relationship defined on them. <set name=TreasuryCodes table=ServiceProviderAccountTreasuryCode lazy=true
I have two entities referenced one to many. When entity framework created the table
I have two entities User and Group: @Entity public class User implements Serializable {
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
I have two entities types: RunContainer parent entity type Run child entity type Run
Consider that i have two entities with following relationship: Entity A <-->> Entity B

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.