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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:35:16+00:00 2026-06-12T17:35:16+00:00

I’m trying to resolve this strange problem since last week but I still haven’t

  • 0

I’m trying to resolve this strange problem since last week but I still haven’t found any solution so I’ve decided to ask here.

I’m going to give a brief of my model for better comprehension:

I’ve a entity called Ruta and it has a collection of images. Every image in Ruta is called ImagenRuta and it has some attributes, including the entity Ruta that owns the ImagenRuta. (OneToManyRelationship)

You can see my entity Ruta here: https://gist.github.com/b0ae0daeaebe4b6323d0

And my entity ImagenRuta here: https://gist.github.com/9064fb2b5f4138423471

My problem is that I can’t update any Ruta from the Controller without lose information about items in the collection of ImagenRuta that the Ruta has. In particular the attribute “imagen” of ImagenRuta is set to null. Other attributes (like ImagenRuta’s id or Ruta’s id) are not lost.

I think the problem might be connected with the type file of “imagen” in ImagenRuta’s form. Because if I set that field as text the attribute “imagen” of entity ImagenRuta is not lost in any ImagenRuta of the collection that the Ruta I want to update has.

Here is my ImagenRuta’s form : https://gist.github.com/0409c630b8c9b3b08068

and my Ruta’s form: http://gist.github.com/74db6231a2b238995fff

And here is the code that I wrote to notice the text field issue:

class ImagenRutaType extends AbstractType {        
    public function buildForm(FormBuilderInterface $builder, array $options) {          
        $builder->add('imagen', 'text', array('required' => true));    
    }        
}

I use the sentences below to restore the original ImagenRuta collection in entity Ruta before modify that entity with form’s information by execute $form->bindRequest($request) :

$anterior = $editForm->getData(); // get ruta entity in form    
$originalImages = $anterior->getImagenes(); // get ImagenRuta collection

and then I merge $originalImages with the collection of ImagenRuta that $editForm contains

$entity = $em->getRepository('RutasBundle:Ruta')->find($id);    
$editForm = $this->createForm(new RutaType(), $entity);    
$editForm->bind($request);    
$imagenesNuevas = $entity->getImagenes()    
// Merge $imagenesNuevas with $originalImages to not to lose any image

The problem is that I can’t restore the previous collection of ImagenRuta that the Ruta had, because when I execute:

$originalImages  = $ anterior-> getImagenes()

in $originalImages I have the collection, yes, but all ImagenRuta in that collection has the “imagen” field set to null (others not) and I don’t know why. As I said above, I think it can be related with the field “imagen” in ImagenRuta’s form is of type ‘file’ because when this happens every imagenRuta I don’t modify from the form comes to the controller with “imagen” field set to null.

Please, see the updateAction in my controller for more detailed information: https://gist.github.com/46e6d0d2f9e188f44030

I have read lots of tutorials, blogs, forums and official cookbook documentation but I haven’t found any solution. I hope somebody can help me.

Regards.

  • 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-12T17:35:17+00:00Added an answer on June 12, 2026 at 5:35 pm

    Your problem is that you are using a single property of your entity to hold both the value of the image that is persisted to the database and the file object that is uploaded in your form. You should have two different properties, one which is persisted to the database and which holds your image filename or path and another property which is not persisted and which will be used for your form file field. Please see this cookbook entry for more information:

    http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.