SonataNewsBundle Entity Relationship Definition - symfony

I'm trying to create a new entity which will have relationship with SonataNewsBundle Post entity. But I can't find any example in the source how to define relation mapping in xml.
I've read all the configuration under Resources/config/doctrine, none of them had entity relation mapping. Or maybe Sonata use other method to define relationship? Give me some clues.

Ahhhh... Found it...
It's in the DependencyInjection.
Sorry for the lame question

Related

Symfony 2 Override Entity and add extra properties

I have entity A and entity B which extend entity A.
Entity A - in vendor bundle.
Entity B - in /src bundle.
I search a lot of time and only solution works for me. It's using ClassMetadataListener on Doctrine Event loadClassMetadata.
But extending on entity B not works. I need add all properties form entity A to entity B.
I can't understand why.
You cannot simply extend a class like normally when using Doctrine2.
Check the documentation on chapter 6. Inheritance Mapping on how to implement inheritance on your entity classes.
You are probably interested in chapter 6.1. Mapped Superclasses.
A mapped superclass is an abstract or concrete class that provides persistent entity state and mapping information for its subclasses, but which is not itself an entity. Typically, the purpose of such a mapped superclass is to define state and mapping information that is common to multiple entity classes.
For this to work you have to use the #MappedSuperclass annotation to your entity base class.
Add #MappedSuperclass annotation in top of A. That would be enough :)

symfony2 annotation documentation

Where can I find documentation for a complete list of annotations possible for different Symfony2 components?
Example, http://symfony.com/doc/current/components/routing/introduction.html here there's not enough information about "options" of the config and documentation about routing via yml in whole.
The same questions for controller annotations. I've found separate references to different annotations possible in controller(http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html, http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/view.html), but no COMPLETE list of possible annotations.
There MUST be something I'm missing, because people somehow know what options to use and how.
You can find all details about annotation in SensioFrameworkExtraBundle documentation (#Route , #Method , #ParamConverter ,#Template ,#Cache and #Security )
If you want the list for your Entity you can read doctrine documentation .

Doctrine2 many repositories for the same entity

For specific needs, I have to create 2 repositories for the same Entity.
The first repository are in the same bundle with the entity and the second, I have to create it in an other bundle but i want to use the same entity with different methodes.
Any idea how can I do that ?
Can't say I see the point, but try this: Symfony 2: Creating a service from a Repository
Create 2 services which extend EntityRepository, construct them correctly and give them the entity reference.
Obviously $em->getRepository('Entity') won't work.
But $this->container->get('repository_service_1') will.
Why do you need this?

Generic comment system in Symfony2

I have in my Symfony 2.1 RC app a simple Comment model (using Doctrine 2). Every comment has a user and a message.
Currently, the CommentBundle manages comments on articles. I'd like it to be more generic to be able to comment any kind of entity without copying code across different bundles dedicated to comments...
For this to work, I also need a way to reference any entity from the comment one. I think having two fields entity_type and entity_id can be a nice solution. However, I can't get the object from these without mapping entity_type to classes manually and using the find method.
So how do I reference an entity from a comment ? And how can I create generic behavior working on several entities ?
You can create a abstract base class entity called Commentable and create entities that inherit Commentable such as Document or Post.
Since Document and Post are derived from Commentable, you can create a one to many relationship between the entities Commentable and Comment respectively.
Make sure to include in your base class ORM annotations for inheritance:
#InheritanceType
#DiscriminatorColumn
#DiscriminatorMap
Examples can be found on Doctrine Project Inheritance Documentation

PHP Composite Design Pattern with Symfony2 and Doctrine

Is there any example for Composite Pattern with Doctrine? I mean PHP source code using Doctrine annotations.
I could find Decorator Pattern here : http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/decorator-pattern.html but no luck about Composite Pattern.
You should be able to do this with Inheritance Mapping (see http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/inheritance-mapping.html) and just normal associations with the type you want (see http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/association-mapping.html)

Resources