I am having an issue with Symfony2 when it comes to removing a record from a table.
I have a table that stores the following: purchaseOrders, purchaseOrderItems, and warehouses
Purchase Order Entity "purchaseOrders"
id|name |
-----------
1 |Test |
Warehouses Entity "warehouses"
id|name |
---------------------
1 |Test Warehouse |
2 |Test Warehouse 2 |
Purchase Order Table Items Entity "purchaseOrderItems"
id|name |purchaseOrder_id|warehouse_id
--------------------------------
1 |Test Item 1 |1 |1
2 |Test Item 2 |1 |1
3 |Test Item 3 |1 |2
The purchaseOrder_id is a many to one relationship linked to a table called "purchaseOrders". The warehouse_id is a many to one relationship linked to a table called "warehouses".
My view.html.twig page is kinda laid out like so:
PurchaseOrder
--------------------------------------
| | Item | Warehouse
--------------------------------------
|1| Test Item 1 | Test Warehouse
|2| Test Item 2 | Test Warehouse
|3| Test Item 3 | Test Warehouse 2
If I remove record #1 from the "warehouses" table I get an error in this view.html.twig template
An exception has been thrown during the rendering of a template ("Entity was not found.") in /Applications/XAMPP/xamppfiles/htdocs/symfonydev/src/WIC/PurchaseOrderBundle/Resources/views/PurchaseOrder/view.html.twig at line 320.
The issue is because when the twig template is trying to access the warehouse "name" it cant find it in the object to render it...
I have tried the following conditional statements and nothing works, I still get that same error:
{% if purchaseOrderItems.warehouses.name != null %}
{{ purchaseOrderItems.warehouses.name }}
{% endif %}
{% if purchaseOrderItems.warehouses.name is defined %}
{{ purchaseOrderItems.warehouses.name }}
{% endif %}
{% if purchaseOrderItems.warehouses.name is not null %}
{{ purchaseOrderItems.warehouses.name }}
{% endif %}
What I need to know is this:
When I remove a "warehouse" how can i make it so that the "purchaseOrderItems" relationship to the "warehouse" doesn't break or puts Null or 0 in the value.
The issue has to be that the purchaseOrderItems cant make the mapping to the warehouse because the record has been deleted.
Please help or advise what I need to do to keep this from happening.
Thanks so much!