Monday, January 4, 2016

Symfony2, Doctrine ORM intermediate complexity transitive relationships


I am not sure how to explain this exactly, but I'll give it my best shot. If anything is unclear, please ask.

In my simplified concept, I have a database where security officers can file reports. Logs are an entity, they have as foreign keys the Client (also an entity), and the Site (entity as well) which the LOG is referring to. However in the ERD, I have the relationship as follows: Many (or none) LOG refer to a (or none) CLIENT, a CLIENT has many (or none) SITE. Or visually in Crows foot notation as such:


Ignore the USERS entity and corresponding relationship for the moment. We are only concerned with the LOG, CLIENT, and SITE entities and cardinalities.


Within Doctrine, my relationships are modeled as follows:

Log.php

/** * @ORM\ManyToOne(targetEntity="GuardShack\ClientBundle\Entity\Site", fetch="EAGER") * @ORM\JoinColumn(referencedColumnName="id", nullable=true) */private $site;
/** * @ORM\ManyToOne(targetEntity="GuardShack\ClientBundle\Entity\Client", fetch="EAGER") * @ORM\JoinColumn(referencedColumnName="id", nullable=true) */private $client;

Site.php
/** * @ORM\ManyToOne(targetEntity="GuardShack\ClientBundle\Entity\Client", fetch="EAGER") * @ORM\JoinColumn(referencedColumnName="id", nullable=true) */private $client;


This feels redundant, and is admittedly slightly different from my ERD.



The desired behavior is to have the create new Log form have drop down selects for client name and site name. When the client name is selected this limits the options in the site drop down select box to only those sites that are owned by that client.

Any "How Tos" for this sort of thing? I know this isn't ground breaking or anything, but I am just having a hiccup with it.



Maybe a better ERD:




No comments:

Post a Comment