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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:57:27+00:00 2026-05-30T22:57:27+00:00

I have three entities, ChannelEntity -> MatchChannelEntity <- MatchEntity, the MatchChannelEntity saves the many

  • 0

I have three entities, ChannelEntity -> MatchChannelEntity <- MatchEntity, the MatchChannelEntity saves the many to many relations between the other two tables, I want a form to list all the channels using checkboxes, and if a match has one the of channels, the checkbox of that channel is selected, how can I do this ?

Here is the Form type code:

class MatchhType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('channels', 'entity', array('label' => 'Channels', 
                                          'class'         => 'Mikay\MikiBundle\Entity\Channel',
                                          'multiple'      => true,
                                          'expanded'      => true,
                                          'query_builder' => function ($repository) 
                                          { 
                                            return $repository->createQueryBuilder('c')->orderBy('c.name', 'ASC'); 
                                          },))

The MatchChannel type:

class MatchChannel
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer $match_id
     * @ORM\ManyToOne(targetEntity="Matchh", inversedBy="channels")
     * @ORM\JoinColumn(name="match_id", referencedColumnName="id", nullable="true")
     */
     private $match;

    /**
     * @var integer $channel_id
     *
     * @ORM\ManyToOne(targetEntity="Channel", inversedBy="mathces")
     * @ORM\JoinColumn(name="channel_id", referencedColumnName="id", nullable="true")
     */
   private $channel;

I will use an example to explain, say, I have three channels: channel A, channel B and channel C, and one match: match M, the match M has one channel A, this relation is saved in the match_channel table, I want a match form to show all the channels, and channel A is checked because it is owned by match M, others stay unchecked

  • 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-30T22:57:29+00:00Added an answer on May 30, 2026 at 10:57 pm

    Ok, I will close this question. That’s because I set up the many to many relation between the two tables wrong, and the correct way is as following(I trimed the code a bit):

    Many to many: One match has many channels and one channel has many matches.

    Match:

    class Match
    {
        /**
         * @ORM\ManyToMany(targetEntity="Channel", inversedBy="matches")
         * @ORM\JoinTable(name="match_channels")
         */
        private $channels;
    

    Channel:

    class Channel
    {
        /**
         * @ORM\ManyToMany(targetEntity="Match", mappedBy="channels")
         */
        private $matches;    
    

    Doctrine will automatically create the cross reference table for you, named MatchChannels.
    Note the JoinTable annonation, it is very important.

    And when you done, you can create a many to many form easily, just like you create other type of forms/fields.

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

Sidebar

Related Questions

I have three tables. Named: Merchants, MerchantNumberX, Numbers (numbers is used by many other
I have three entities: EntityA, EntityB and EntityC connected with to-many relationships. See schema
I have a case where i have three entities with one-to-many and one-to-many relationships:
I have three entities A, B, C. A has many Bs and a C,
I have three related entities: a user has many device a user has a
I have three entities: Log, Employee, and Agency Log with a many to one
I have three linked Entities (Categories->Types->Classes) with one to many relationship. Is it possible
I have three Entity Objects. The relationship between these entities is kinda love triangle!
I have three entities ClassC, ClassS and ClassSA. I want to apply group by
I have three entities: User, Office and PhoneNumber. The user has many phone numbers,

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.