Hi I read this article http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html yet I'm not quiet sure how to accomplish the following:
I have a "user"-Table, a "man"-Table and a "woman"-table.
I want my php classes Man and Woman extend the User Object.
Annotationmapping:
namespace Core\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* #ORM\Table(name="user", uniqueConstraints={#ORM\UniqueConstraint(name="email_UNIQUE", columns={"email"}), #ORM\UniqueConstraint(name="username_UNIQUE", columns={"username"})})
* #ORM\Entity
*/
class User
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="first_name", type="string", length=255, nullable=true)
*/
private $firstName;
/**
* #var string
*
* #ORM\Column(name="middle_name", type="string", length=255, nullable=true)
*/
private $middleName;
/**
* #var string
*
* #ORM\Column(name="last_name", type="string", length=255, nullable=true)
*/
private $lastName;
/**
* #var string
*
* #ORM\Column(name="username", type="string", length=255, nullable=false)
*/
private $username;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* #var \DateTime
*
* #ORM\Column(name="created_at", type="datetime", nullable=true)
*/
private $createdAt;
/**
* #var \DateTime
*
* #ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt;
/**
* #var \DateTime
*
* #ORM\Column(name="last_login", type="datetime", nullable=false)
*/
private $lastLogin;
/**
* #var string
*
* #ORM\Column(name="login_hash", type="string", length=255, nullable=true)
*/
private $loginHash;
/**
* #var boolean
*
* #ORM\Column(name="is_premium", type="boolean", nullable=false)
*/
private $isPremium = '0';
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Core\Entity\Bill", inversedBy="user")
* #ORM\JoinTable(name="user_has_bill",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="bill_id", referencedColumnName="id")
* }
* )
*/
private $bill;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Core\Entity\Picture", inversedBy="user")
* #ORM\JoinTable(name="user_has_picture",
* joinColumns={
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="picture_id", referencedColumnName="id")
* }
* )
*/
private $picture;
/**
* Constructor
*/
public function __construct()
{
$this->bill = new \Doctrine\Common\Collections\ArrayCollection();
$this->picture = new \Doctrine\Common\Collections\ArrayCollection();
}
}
Woman:
namespace Core\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Woman
*
* #ORM\Table(name="woman", indexes={#ORM\Index(name="fk_woman_user1_idx", columns={"user_id"})})
* #ORM\Entity
*/
class Woman
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
*/
private $id;
/**
* #var \Core\Entity\User
*
* #ORM\Id
* #ORM\GeneratedValue(strategy="NONE")
* #ORM\OneToOne(targetEntity="Core\Entity\User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Core\Entity\Cart", inversedBy="woman")
* #ORM\JoinTable(name="woman_has_cart",
* joinColumns={
* #ORM\JoinColumn(name="woman_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="cart_id", referencedColumnName="id")
* }
* )
*/
private $cart;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Core\Entity\Interest", inversedBy="woman")
* #ORM\JoinTable(name="woman_has_interest",
* joinColumns={
* #ORM\JoinColumn(name="woman_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="interest_id", referencedColumnName="id")
* }
* )
*/
private $interest;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="Core\Entity\Man", inversedBy="woman")
* #ORM\JoinTable(name="woman_has_man",
* joinColumns={
* #ORM\JoinColumn(name="woman_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* #ORM\JoinColumn(name="man_id", referencedColumnName="id")
* }
* )
*/
private $man;
/**
* Constructor
*/
public function __construct()
{
$this->cart = new \Doctrine\Common\Collections\ArrayCollection();
$this->interest = new \Doctrine\Common\Collections\ArrayCollection();
$this->man = new \Doctrine\Common\Collections\ArrayCollection();
}
}
The man mapping looks (for now) the same as the woman.
Here a little Snippet from MysqlWorkbench http://s14.directupload.net/images/131013/fbg7okyn.png
The basic idea is this:
Men and Women share some common logic and individual logic. For example take a login. Men and Women need an email and a password to log in. Since it's redundant to implement the same login logic twice I thought of creating a more abstract class, the User, which is where I want to put everything which applies to men and women, like name, email, password, login logic etc...
This is where it gets tricky with doctrine. Men and women will have individual fields to store in the database, yet they still need their "common data"(name, password etc...), so a simple class Man extends User might not work out correctly. I store the corresponding id of the User on men and women. So there is an identification.
What I had in mind is, if I do $men->getPassword() it should use the getPassword()function of the corresponding User object.
I hope I cleared up my intend.
Kind Regards and thank you for digging through.
i have done this what you're looking for in one of my projects once, It's done not too good code wise, but the mapping is fine ;) Please check this link
Item.php.dist would be your User Entity
(Property|Vehicle).php.dist would be your Man / Women Entity
Please notice that the Property Discriminator Mapping is missing within the code examples. I do it differently in the application ;)
Ultimately you wouldn't want to have separate "Tables" on your SQL Server. It all belongs to the Superclass "User" and therefore belongs to the User-Table. You will extends the UserTable and use DiscriminatorMapping to map specific entities.
Note: A Man can not be editted to become a Woman! You'd have to kill the man and give birth to a woman :P
Imagina this Model:
User
*id
-name
-surname
Man extends User
-pc_power
Woman extends User
-nail_color
Your DB-Schema would look like this:
Table User:
*id (pk)
-discriminator (not nullable) (value: man or woman)
-name (not nullable)
-surname (not nullable)
-pc_power (nullable as far as DB is concerned)
-nail_color (nullable as far as DB is concerned)
You do not need 3 tables to mod your models like this. It makes literally no sense to do this. It just slows your Queries down by quite a bit.
Now a Dataset could look like this:
A Man: (1, man, john, doe, 4ghz, null)
A Woman: (2, woman, john, doe, null, pink)
Now on Doctrines side of things you do Queries against the USER-Entity
$entity = $userRepository->find(1);
echo get_class($entity); // returns "Man"
$entity = $userRepository->find(2);
echo get_class($entity); // returns "Woman"
Does that make things more clear, because otherwise i'm simply unable to help you :P
Related
I have a Forum Entity that may contain sub forums which will be of the same class(Forum) . i am having trouble with establishing this relation .
the code below is what i have tried so far in my Forum class
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=false)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=5000, nullable=false)
*/
private $description;
/**
* #ORM\Column(type="string")
*
* #Assert\NotBlank(message="Please, upload the forum wallpaper as a PNG file.")
* #Assert\File(mimeTypes={ "image/png" })
*/
private $wallpaper;
/**
* #var \DateTime
*
* #ORM\Column(name="added_date", type="datetime", nullable=false)
*/
private $addedDate;
/**
* #var array
*
* #ORM\ManyToMany(targetEntity="AppBundle\Entity\User", cascade={"remove"})
*/
private $moderators;
/**
* #var Forum[]
* #ORM\OneToMany(targetEntity="Forum", mappedBy="id", cascade={"all"}, orphanRemoval=true)
*/
private $subForums;
/**
* #var \AppBundle\Entity\User
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\User")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $userId;
the problem after updating the database scheme i didnt end up with any table linkin forums and subforums so i am confused how can i add a sub forum to an exsiting forum later on . Any help is much appriciated
I believe what you are looking for is a One-To-Many self-referencing mapping
So change your $subForums like so:
/**
* #var Forum[]
* #ORM\OneToMany(targetEntity="Forum", mappedBy="parentForum", cascade={"all"}, orphanRemoval=true)
*/
private $subForums;
and add $parentForum, like so:
/**
* #ManyToOne(targetEntity="Forum", inversedBy="subForums")
* #JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parentForum;
In my application I have a cigar humidor entity that has 8 slots. I would like each slot to hold an instance of any given of the hundreds of cigars there are to pick from.I can add a cigar to the cigar slot once for one humidor but I can not swap to a different humidor and add the same cigar to the slot1. I was thinking that with being in different humidors that it would surely not be an issue but I am now getting the exception "An exception occurred while executing 'UPDATE humidor SET slot_1 = ? WHERE id = ?' with params [2, 8]:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2' for key 'UNIQ_4AE64E7F3CF622F8'"' I'm not exactly an expert with doctrine and am not totally sure on how I should go about modeling this. Any advice would be fantastic.
Here is the humidor with the slots
/**
* Humidor
*
* #ORM\Table(name="humidor")
* #ORM\Entity(repositoryClass="AppBundle\Repository\HumidorRepository")
*/
class Humidor
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
/**
* #ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="humidors")
* #ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_1", referencedColumnName="id")
*/
private $slot1;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_2", referencedColumnName="id")
*/
private $slot2;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_3", referencedColumnName="id")
*/
private $slot3;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_4", referencedColumnName="id")
*/
private $slot4;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_5", referencedColumnName="id")
*/
private $slot5;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_6", referencedColumnName="id")
*/
private $slot6;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_7", referencedColumnName="id")
*/
private $slot7;
/**
* #ORM\OneToOne(targetEntity="Cigar")
* #ORM\JoinColumn(name="slot_8", referencedColumnName="id")
*/
private $slot8;
and then my cigar entity
/**
* Cigar
*
* #ORM\Table(name="cigar")
* #ORM\Entity(repositoryClass="AppBundle\Repository\CigarRepository")
* #ORM\HasLifecycleCallbacks()
*/
class Cigar
{
/**
* #ORM\PrePersist()
*/
public function onPrePersist(){
$this->setName($this->getManufacturer()->getName() . " " . $this->getVariant());
}
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var int
*
* #ORM\Column(name="gauge", type="integer")
*/
private $gauge;
/**
* #var string
*
* #ORM\Column(name="body", type="string", length=255)
*/
private $body;
/**
* #var string
*
* #ORM\Column(name="wrapper_country", type="string", length=255)
*/
private $wrapperCountry;
/**
* #var string
*
* #ORM\Column(name="variant", type="string", length=255)
*/
private $variant;
/**
* #var string
*
* #ORM\Column(name="description", type="text")
*/
private $description;
/**
* #var string
*
* #ORM\Column(name="filler_country", type="string", length=255)
*/
private $fillerCountry;
/**
* #ORM\ManyToOne(targetEntity="Manufacturer", inversedBy="cigars")
* #JoinColumn(name="manufacturer_id", referencedColumnName="id")
*/
private $manufacturer;
/**
* #ORM\ManyToOne(targetEntity="Wrapper", inversedBy="cigars")
* #JoinColumn(name="wrapper_id", referencedColumnName="id")
*/
private $wrapper;
/**
* #ORM\ManyToOne(targetEntity="Shape", inversedBy="cigars")
* #JoinColumn(name="shape_id", referencedColumnName="id")
*/
private $shape;
/**
* #ORM\Column(type="string")
*
*/
private $image;
/**
* #var string
* #ORM\Column(type="string")
*/
private $name;
As you have one-to-one mapping, doctrine creates unique index for those columns. Let's consider this example (I've left only single slot as it's enough for this example):
id slot_1
1 11
2 12
This means that you have 2 cigars with IDs 11 and 12 assigned to humidor 1 and 2 respectively. There is unique index on slot_1 column here - this guarantees that any single cigar does not belong to two different humidors.
If you try to switch them, following SQL statements are generated:
UPDATE humidors SET slot_1 = 12 WHERE id = 1;
UPDATE humidors SET slot_1 = 11 WHERE id = 2;
Unfortunately, first statement cannot be executed, as database does not allow cigar 12 to be in both humidor 1 and 2 at once.
Simplest solution would be to change one-to-one relations to many-to-one (in your $slotX fields) - this would remove unique constraints, otherwise it would work the same in your example as there is no reverse relation. Furthermore, as there are 8 slots and cigars cannot belong to several of these (if I correctly understand), rules are already not strictly controlled by the database itself.
Another way would be to switch those with temporary null values etc. but it's even harder with doctrine, as you would need two separate flush statements and, optionally, manually wrapping these in a transaction to avoid inconsistent state in the database.
I'm trying to create a "OneToMany" bidirectional association in my project but when I execute "doctrine:schema:update" nothing happens.
If I create this association directly from Sequel Pro and run the update schema command, that changes dissapear... :/
The relations is:
- One "id" from Customers Table with many "customer_id" form Control table.
Here is the Customers code:
<?php
namespace Ourentec\CustomersBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Customers
*
* #ORM\Table()
* #ORM\Entity
*/
class Customers
{
/* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=100)
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=100)
*/
private $lastname;
/**
* #var string
*
* #ORM\Column(name="address", type="text")
*/
private $address;
/**
* #var string
*
* #ORM\Column(name="phone", type="string", length=100)
*/
private $phone;
/**
* #var string
*
* #ORM\Column(name="pass", type="string", length=100)
*/
private $pass;
/**
* #var string
*
* #ORM\Column(name="tasks", type="text")
*/
private $tasks;
/**
* #var string
*
* #ORM\Column(name="status", type="string", length=100)
*/
private $status;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=100)
*/
private $email;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var string
*
* #ORM\Column(name="location", type="string", length=100)
*/
private $location;
/**
* #ORM\OneToMany(targetEntity="Control", mappedBy="customers")
*/
private $customer_id;
public function __construct()
{
$this->customer_id = new ArrayCollection();
}
And the Control code:
<?php
namespace Ourentec\CustomersBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Control
*
* #ORM\Table()
* #ORM\Entity
*/
class Control
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="customer_id", type="integer")
*
* #ORM\ManyToOne(targetEntity="Customers", inversedBy="control")
* #ORM\JoinColumn(name="customer_id", referencedColumnName="id")
*/
private $customerId;
/**
* #var integer
*
* #ORM\Column(name="user_id", type="integer")
*/
private $userId;
/**
* #var \DateTime
*
* #ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* #var integer
*
* #ORM\Column(name="seen", type="smallint")
*/
private $seen;
I followed the documentation from this 2 websites
http://symfony.com/doc/current/book/doctrine.html
http://librosweb.es/libro/symfony_2_x/capitulo_8/relaciones_y_asociaciones_de_entidades.html
But I don't know why it does not work..
Any idea will be appreciated :)
Mapping are not correct, I will try to explain how it works.
In Customers entity (you should rename it to Customer, entites names are singular)
/**
* #ORM\OneToMany(targetEntity="Control", mappedBy="customer")
*/
private $controls;
Mapped by option defines field name in the other entity.
/**
* #var integer
*
* #ORM\Column(name="customer_id", type="integer")
*
* #ORM\ManyToOne(targetEntity="Customers", inversedBy="controls")
* #ORM\JoinColumn(name="customer_id", referencedColumnName="id")
*/
private $customer;
Same thing with inversedBy.
In Customers entity you also need to init controls var as an ArrayCollection:
public function __construct()
{
$this->controls = new ArrayCollection();
}
With these mappings schema should be updated correctly.
For more info, check doctrine docs.
I have entity developer and comment and relationship Many comment to One developer. And I need form when I see all comment for developer and edit - add, delete in DB . What are the solutions to this problem
entity Comment:
class Comments
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Developer", inversedBy="comments")
* #ORM\JoinColumn(name="talent_id", nullable = true, referencedColumnName="id")
* */
protected $talent;
/**
* #var string
*
* #ORM\Column(name="added_by", type="string", length=10, nullable=true)
*/
private $added_by;
/**
* #var string
*
* #ORM\Column(name="comment", type="string", length=10, nullable=true)
*/
private $comment;
entity Developer:
class Developer extends CustomUser
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/////
/**
* #ORM\OneToMany(targetEntity="Comments", mappedBy="talent", cascade={"persist", "remove"})
*/
protected $comments;
Maybe need form in form but how to do this?
You are looking for field type collection.
Example usage of collection type
class Comments
{
....
/**
*
*#ORM\ManyToOne(targetEntity="Developer", inversedBy="developer_to_comments")
* #ORM\JoinColumn(name="developer_to_comments_id", referencedColumnName="id", nullable=false)
*
*/
private $comments_to_developer;
...
}
And class Developer
class Developer extends CustomUser
{
....
/**
*
* #var ArrayCollection
* #ORM\OneToMany(targetEntity="Comments", mappedBy="comments_to_developer", cascade={"remove"})
*/
private $developer_to_comments;
public function __construct()
{
$this->developer_to_comments = new ArrayCollection();
}
....
}
And don't forget use Doctrine\Common\Collections\ArrayCollection
so, i have two entities: Genre and Game
Genre.php
<?php
namespace Acme\Bundle\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Genre
*
* #ORM\Table(name="genre")
* #ORM\Entity
*/
class Genre
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=64, nullable=false)
*/
protected $name;
/**
* #var string
*
* #ORM\Column(name="display", type="string", length=64, nullable=false)
*/
protected $display;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=false)
*/
protected $description;
/**
* #var ArrayCollection|Game[]
*
* #ORM\ManyToMany(targetEntity="Game", inversedBy="genres", cascade={"persist"})
*/
protected $games;
// ... Irrelevant Constructor and following getters/setters
}
Game.php
<?php
namespace Acme\Bundle\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Game
*
* #ORM\Table(name="game")
* #ORM\Entity
*/
class Game
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=256, nullable=false)
*/
protected $name;
/**
* #var string
*
* #ORM\Column(name="display", type="string", length=256, nullable=false)
*/
protected $display;
/**
* #var string
*
* #ORM\Column(name="description", type="text", nullable=false)
*/
protected $description;
/**
* #var ArrayCollection|Genre[]
*
* #ORM\ManyToMany(targetEntity="Genre", inversedBy="games", cascade={"persist"})
* #ORM\JoinTable(name="genre_game",
* joinColumns={#ORM\JoinColumn(name="genre_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="game_id", referencedColumnName="id")}
* )
*/
protected $genres;
/**
* #var ArrayCollection|Platform[]
*
* #ORM\ManyToMany(targetEntity="Platform", inversedBy="games", cascade={"persist"})
* #ORM\JoinTable(name="platform_game",
* joinColumns={#ORM\JoinColumn(name="platform_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="game_id", referencedColumnName="id")}
* )
*/
protected $platforms;
/**
* #var Image[]
*
* #ORM\OneToMany(targetEntity="Image",mappedBy="game_id", cascade={"persist"})
*/
protected $images;
}
When i run php app/console doctrine:schema:create or update, it creates all of the needed join tables I specified above, but it also creates genre_genre
This table is always empty, and doesnt seem to do anything, and prevents me from running php app/console doctrine:schema:update's later, and its trying to add an index to it that already exists
Anyone see what I'm doing wrong?
Game->genres and Genre-game are inversed by each other, which is invalid - one needs to be owning. I believe there is a doctine:schema:validate command you would find useful.
Sir, I think you have made many to many relation(bidirectional) in those mapping classes. According to doctrine documentation that will create that table for relation of those Game and Genre like in the example.
You can create the db table then create the mapper class to verify with generate-entities. This way you can verify the schema and the mapping.