Created
November 1, 2017 15:21
-
-
Save alpha1125/2fda174807fdd36d6b74d18132b5086f to your computer and use it in GitHub Desktop.
Create one to many relationship, this is a template, to generate the code needed to make oneToMany relationships. Change $A and $B accordingly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$A = 'Product'; | |
$B = 'Feature'; | |
echo <<< EOD | |
<pre> | |
/** | |
* @See: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-bidirectional | |
* as of 2017-11-01 | |
* | |
* \$A = one | |
* \$B = many | |
* | |
* ONE to Many | |
* \$A => \$B | |
* $A => $B | |
* | |
*/ | |
</pre> | |
EOD; | |
$Bs = $B . 's'; | |
$a = lcfirst($A); | |
$b = lcfirst($B); | |
$bs = lcfirst($Bs); | |
$string = <<< EOD | |
<?php | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** @ORM\Entity */ | |
class $A | |
{ | |
// ... | |
/** | |
* One $A has Many $Bs. | |
* @ORM\OneToMany(targetEntity="$B", mappedBy="$a") | |
*/ | |
protected \$$bs; | |
// ... | |
public function __construct() | |
{ | |
\$this->$bs = new ArrayCollection(); | |
} | |
// ... GETTERS ... | |
// ... SETTERS ... | |
} | |
/** @Entity */ | |
class $B | |
{ | |
// ... | |
/** | |
* Many $Bs have One $A. | |
* @ORM\ManyToOne(targetEntity="$A", inversedBy="$bs") | |
*/ | |
protected \$$a; | |
// ... | |
// ... GETTERS ... | |
// ... SETTERS ... | |
} | |
EOD; | |
ini_set("highlight.comment", "#008000"); | |
ini_set("highlight.default", "#000000"); | |
ini_set("highlight.html", "#808080"); | |
ini_set("highlight.keyword", "#0000BB; font-weight: bold"); | |
ini_set("highlight.string", "#DD0000"); | |
highlight_string($string); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment