I am using Doctrine "in reverse" in that I have some legacy code that I am 
refactoring, 
and I am fitting in Doctrine to be on top of already existing tables.

So for example I have a table like so:

item(id, description, motor_id, product_id, drive_id);

I also have the corresponding tables for each of the foreign keys (not 
shown).
I have defined most but not all entities for the tables.  For example, I 
have one for the Product, but not for Motor or Drive.

I have noted that Using Doctrine, I can (for product_id, as an example):

   1. just leave it as an integer, without setting up an Entity
   2. set up a ManyToOne connection for the Product foreign key and treat 
   that property as an Entity

*Caveats*

.. I have tried some of this and I have found that using Entity so far can 
be a bit of an inconvenience.


Example without Entity:  I have code like so:

$productId = 44; //already known in the code
$db->query("update item set description = '...', product_id = $productId 
where id = $id;");


Transforming the above to Doctrine is easy enough.  And without an Entity 
for $productId property, product_id becomes just another thing to set, like 
so:

$item->setProductId($productId);


But when using an Entity instead there's a bit more work to be done.  I use 
something like so

//since $productId is already known I don't want to read it from DB again, 
so I use getReference()
$product = $this->em->getReference(Product::class, $productId);
$item->setProduct($product);

*Question*

In the grand scheme of things, I presume Doctrine will advocate the 
approach of using Entities for foreign keys (sometimes at the expense of 
setting up extra Proxies like above, or even just using $this->em->find(), 
to populate the foreign key Entity)

But, when I already have legacy code that's using known foreign keys, is 
using Entities worth it?
aka the legacy code already has the plumbing for integer keys, and 
rewriting for Entities will take a bit of work.  I am seeking some 
justification for that work, other than "It's the Doctrine Way, make it so".

-- 
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 doctrine-user+unsubscr...@googlegroups.com.
To post to this group, send email to doctrine-user@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to