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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:36:51+00:00 2026-06-08T05:36:51+00:00

I think I’m missing something obvious with doctrine relationship mapping. I have two models,

  • 0

I think I’m missing something obvious with doctrine relationship mapping.

I have two models, Microsite and Page (one to many, page only belongs to one site).

/*
 ...

 * @ORM\Table()
 * @ORM\Entity(repositoryClass="EP\PreReg\DataBundle\Entity\MicrositeRepository")
 */
class Microsite
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    ...

    /**
     * @ORM\OneToMany(targetEntity="Page", mappedBy="site")
     */
    private $pages;


    public function __construct() {
        $this->pages = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getPages() {
        return $this->pages;
    }

    public function addPage($page) {
        $this->pages[] = $page;
    }
/*
 * @ORM\Table()
 * @ORM\Entity
 */
class Page
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $title
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title;

    /**
     * @var string $slug
     *
     * @ORM\Column(name="slug", type="string", length=100)
     */
    private $slug;

    /**
     * @ORM\ManyToOne(targetEntity="Microsite", inversedBy="pages")
     */
    private $site;

The schema looks good:

CREATE TABLE Page (id INT AUTO_INCREMENT NOT NULL, site_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, slug VARCHAR(100) NOT NULL, INDEX IDX_B438191EF6BD1646 (site_id), PRIMARY KEY(id)) ENGINE = InnoDB;

CREATE TABLE Microsite (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, shortCode VARCHAR(20) NOT NULL, subdomain VARCHAR(100) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;

ALTER TABLE Page ADD CONSTRAINT FK_B438191EF6BD1646 FOREIGN KEY (site_id) REFERENCES Microsite(id)

but I can’t get the fixtures to load properly (I had them working, but even then I could not get the related pages per site.

My question is: Are these annotations correct, and how do I correctly add data, and retrieve pages from a given site?

Fixtures are:

class LoadMicrositeData implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {

        $site = new Microsite();
        $site->setName('Microsite Name');
        $site->setShortCode('MIC');
        $site->setSubdomain('micro');

        $homepage = new Page();
        $homepage->setSlug('/');
        $homepage->setTitle('Welcome');

        $site->addPage($homepage);

        $manager->persist($site);
        $manager->persist($homepage);

        $manager->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-06-08T05:36:53+00:00Added an answer on June 8, 2026 at 5:36 am

    You need to set the $site property on the Page. I advise you to delegate the creation of a Page to the Microsite:

    class Microsite
    {
        // ...
    
        public function addPage() {
            $page = new Page($this);
            $this->pages->add($page);
            return $page;
        }
    }
    
    class Page
    {
        // ...
    
        public function __construct(Microsite $site) {
            $this->site = $site;
        }
    }
    

    You would then use it this way:

    $site = new Microsite();
    $site->setName('Microsite Name');
    $site->setShortCode('MIC');
    $site->setSubdomain('micro');
    
    $homepage = $site->addPage();
    $homepage->setSlug('/');
    $homepage->setTitle('Welcome');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Think that I have many activities,and all I want is this: I have a
I think I'm missing something basic here. Why is the third IF condition true?
I think I'm missing something basic here. Any explanation or pointers to previously asked
I think I'm running across a conflict due to names: Two models: store coupon
Think Design: I have many applications that share the same user database! Other tables
i think this is an easy one for you: I have a Controller in
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
I think I have found a bug when setting or getting the Me.Top property

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.