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

  • Home
  • SEARCH
  • 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 8460209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:32:34+00:00 2026-06-10T13:32:34+00:00

I am currenty struggling with the forms and the held entities, because I am

  • 0

I am currenty struggling with the forms and the held entities, because I am not able to access attributes from a related entity within a form.

form.get('value') // access current entity
form.get('value').relatedEntity  // (access the related entity)
form.get('value').relatedEntity.property // is not working

I would like to explain my whole scenario more in a detail, because I think my current solution is not the best and maybe I can avoid the whole issue with designing my forms a little bit different.

I basically followed the instruction on how to submit multiple entities within one form https://groups.google.com/forum/?fromgroups#!topic/symfony2/DjwwzOfUIuQ%5B1-25%5D

First, here are my Entities:

//@ORM\Entity
class Game {

    //@ORM\Column(name="scoreT1", type="integer", nullable=true)
    private $scoreT1;

    //@ORM\Column(name="scoreT2", type="integer", nullable=true)
    private $scoreT2;


    //@ORM\OneToOne(targetEntity="Bet", mappedBy="game")
    private $bet;
}
//@ORM\Entity
class Bet {
    //@ORM\Column(name="scoreT1", type="integer", nullable=true)
    private $scoreT1;

    //@ORM\Column(name="scoreT2", type="integer", nullable=true)
    private $scoreT2;

    // @ORM\OneToOne(targetEntity="Game", inversedBy="bet")
    private game;
}

And these are my Forms:

class GamesListType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('bets', 'collection',array(
                      'required' => false,
                      'allow_add' => false,
                      'type' => new BetType()
        ))
        ;
    }

    public function getDefaultOptions(array $options)
    {
        return array('data_class' => 'Strego\TippBundle\Form\Model\BetCollection');
    }
}
class BetType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('scoreT1')
                ->add('scoreT2');
        ;
    }

     public function getDefaultOptions(array $options)
    {
        return array('data_class' => 'Strego\TippBundle\Entity\Bet');
    }
}

In order to get the bets from the “mainEntity” in the GamesListForm I created a dedicated Collectionclass:

use Doctrine\Common\Collections\ArrayCollection;
class BetCollection extends ArrayCollection {

    public function getBets(){
        return $this;//->toArray();
    }
}

This is more the environment I’m working on. My requirement is to somehow show a list of games and a form to bet on this games. I currently try to achieve it like this:

{% for bet in form.bets %}
     bet.get('value').game.scoreT1  // <-- this is my current issue
        <div class="row">{{ form_widget(item) }}</div>
{% endfor %}

I am explaining the whole scenario, because I would like some input how to achieve the list of games and the forms next to it. Another Idea was to have 3 Forms: GamesList / Game / Bet, but somehow i ran into an endlessloop which was stopped by symfony. Is there a general issue with 3 layers in forms?

  • 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-10T13:32:36+00:00Added an answer on June 10, 2026 at 1:32 pm

    I figured it out. The issue was somewhere else.
    Related entities and their properties can easily accessed via:

    form.get('value').relatedEntity.property
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code is from an Access 2007 project I've been struggling with. The actual
I am struggling with Javascript. Most of my problems do not arise from lack
I am trying to get a basic form to work and am struggling because
Because I'm currently struggling to learn IBM Rational ClearCase, I'd like to hear your
I'm currently struggling with this Collection was modified; enumeration operation may not execute issue.
I'm currently struggling with the development of a todo list (mostly unimportant) within which
I am currently struggling to call a non python program from a python script.
I have a form with many inputs, but not all inputs must be filled
We are beginning the process of moving from Web Forms to MVC for all
I'm struggling to get a $.ajax call to correctly send some form data to

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.