Yesterday i had a discussion with my colleague about a strategy to deal
with polymorph relations (which are not really supported by MySql/Doctrine2)
We have the following situation: We have a model which has a child / parent
relation:
interface MenuInterface
{
public function getName();
public function getDescription();
//...
// now important stuff:
/**
* @return MenuInterface[]
*/
public function getChildren();
/**
* @return MenuInterface|null
*/
public function getParent();
}
..and we want to use and yet unknown tree structure implementation (think
of materialized path, nested set etc)
By this time we want just began to implement other code using MenuInterface
In code like https://github.com/KnpLabs/materialized-path my code would be
aware of implementation details of the tree. Every time I'd to fetch the
children or the parent, I have to use that repository (at least i need to
run some methods to build a tree.
My idea was the following:
Writing an implementation of MenuItem using the MaterializedPath strategy
with "intelligent" implementations of *getParent()* and *getChildren()*
For this i want to use a trait like MaterializedPathTrait which implements
both methods. Internally i would set needed objects (like nested set
repository), perhaps with a postLoad event subscriber.
Now every time i do a *getChildren()* or a *getParent()* on my Menu object
I'm not aware this happens via a nested set strategy or materialized path
or simple self-referencing relation.
The argument of my colleague is: Doctrine2 is not an Active Record
component and my implementation would break that concept.
My argument is: Clients of my MenuInterface are not aware of implementation
details and not depending on nested set repository etc to use *getParent()*
and *getChildren()*.
*What are you thinking?*
*http://stackoverflow.com/questions/28582485/models-with-unknown-tree-strategy-getparent-getchildren-strategy*
Be fair i'd post that answer back to StackOverflow
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.