I have following entities:
class File{
private $fileId;
private $filePath;
}
class User{
private $userId;
private array $userFiles;
}
class Order{
private $orderId;
private array $orderFiles;
}
I have three entities: File, User, Order.
Now I want to link User to File as one2many relationships. One user can have multiple files. And the same with Order - connect Order with File via one2many relationship - one order can have multiple files.
My question is, do I need to create two(one for relation with User, and one for relation with Order) tables for the File entity?
Or I can merge these two tables into one and for instance, add field type in File entity, which will tell us to which entity(User/File) it belongs.
Here you have my uncomplete mapping in xml
<entity name="File" table="file">
<id name="fileId" type="uuid">
<generator strategy="NONE" />
</id>
<field name="filePath />
</entity>
<entity name="User" table="user">
<id name="userId" type="uuid">
<generator strategy="NONE" />
</id>
<one-to-many field="userFiles" target-entity="File" mapped-by="herewhat?" >
<cascade>
<cascade-persist />
</cascade>
</one-to-many>
</entity>
<entity name="Order" table="order">
<id name="orderId" type="uuid">
<generator strategy="NONE" />
</id>
<one-to-many field="orderFiles" target-entity="File" mapped-by="herewhat?" >
<cascade>
<cascade-persist />
</cascade>
</one-to-many>
</entity>
I would prefer the second option - everything in one table if it is possible.
Thanks in advance!