Tuesday, January 5, 2016

TODO:

Read these later:

http://stackoverflow.com/questions/17436678/manytomany-relationships-with-doctrines-querybuilder-and-symfony2

http://stackoverflow.com/questions/5197710/symfony-generator-forms-doctrine-and-mn-relationships

http://stackoverflow.com/questions/15977529/symfony2-doctrine-and-forms-persisting-the-data-of-both-sides-of-a-1-relat


Add commentary regarding my problem.

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:




Sunday, January 3, 2016

Symfony2 and Doctrine issues...



Symfony2 issues...



Here is what happens when I try to run the command to generate entities for this




However it works fine for other php classes:



Here is the code in question that I am trying to generate entities from:
Any ideas?

Log.php
<?php
namespace GuardShack\ReportBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use GuardShack\UserBundle\Entity\User;
use GuardShack\ClientBundle\Entity\Site;
use GuardShack\ClientBundle\Entity\Client;
/**
 * Log
 *
 * @ORM\Table(name="gs_log")
 * @ORM\Entity(repositoryClass="GuardShack\ReportBundle\Entity\LogRepository")
 */
class Log
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @var string
     *
     * @ORM\Column(name="title", type="string", length=255)
     */
    private $title;
    /**
     * @var string
     *
     * @ORM\Column(name="body", type="string", length=255)
     */
    private $body;
    /**
     * @var \DateTime
     *
     * @ORM\Column(name="dtg", type="datetime")
     */
    private $dtg;
    /**
     * @ORM\ManyToOne(targetEntity="GuardShack\UserBundle\Entity\User", fetch="EAGER")
     * @ORM\JoinColumn(referencedColumnName="id", nullable=false)
     */
    private $author;
    /**
     * @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;
    /**
     * @ORM\ManyToOne(targetEntity="GuardShack\ReportBundle\Entity\Type", fetch="EAGER")
     * @ORM\JoinColumn(referencedColumnName="id", nullable=true)
     */
    private $type;
    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set title
     *
     * @param string $title
     *
     * @return Log
     */
    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }
    /**
     * Get title
     *
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }
    /**
     * Set body
     *
     * @param string $body
     *
     * @return Log
     */
    public function setBody($body)
    {
        $this->body = $body;
        return $this;
    }
    /**
     * Get body
     *
     * @return string
     */
    public function getBody()
    {
        return $this->body;
    }
    /**
     * Set dtg
     *
     * @param \DateTime $dtg
     *
     * @return Log
     */
    public function setDtg($dtg)
    {
        $this->dtg = $dtg;
        return $this;
    }
    /**
     * Get dtg
     *
     * @return \DateTime
     */
    public function getDtg()
    {
        return $this->dtg;
    }
    /**
     * @return User
     */
    public function getAuthor()
    {
        return $this->author;
    }
    /**
     * @param User $author
     */
    public function setAuthor(User $author)
    {
        $this->author = $author;
    }
}