Noob here. I would say I can see the peak of the curve but I still have a ways to go.
I have an entity (tblxchangecategories) referencing a categories table:
This is related to an entity (tblxchangecategory_hier) referencing a category hierarchy table:
The relationship is self-referencing.
There are 6 major categories that are the parents and the remaining categories (36) are all children.
This is how I've defined their relationship in the entity file (tblxchangecategories):
/**
* @OneToMany(targetEntity="TblXchangecategories", mappedBy="children")
**/
private $parent;
/**
* @ManyToOne(targetEntity"TblXchangecategories", inversedBy="parent")
* @JoinTable(name="tbl_xchangecategory_hier",
* joinColumns={@joinColumn(name="hier_parent", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="hier_child", referencedColumnName="id")}
*/
private $children;
And in the other entitiy file (tblxchangecategory_hier):
/**
* @var \WorkoutExchange\WXCoreBundle\Entity\TblXchangecategories
*
* @ORM\OneToMany(targetEntity="WorkoutExchange\WXCoreBundle\Entity\TblXchangecategories")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="hier_parent", referencedColumnName="id")
* })
*/
private $hierParent;
/**
* @var \WorkoutExchange\WXCoreBundle\Entity\TblXchangecategories
*
* @ORM\ManyToOne(targetEntity="WorkoutExchange\WXCoreBundle\Entity\TblXchangecategories")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="hier_child", referencedColumnName="id")
* })
*/
private $hierChild;
Using the following code I'm able to retrieve all of the categories in a flattened array (no relationships):
$categories = $em->getRepository('WorkoutExchangeWXCoreBundle:TblXchangecategories')->findAll();
I can set up the view, so that's no problem, it's getting the data out of the database that's causing me troubles.
I've seen references to the ->getChildren()
function in several of my searches but I don't have this function in either of my entity definition files.
What I want is to get all of the entities populated so that when I display them I can use the parents as headers and the children under the parents something like this:
Thanks for any help.