0
votes

I have displayed the relational database data's in drop down that's working properly

But when i try to insert the data's to another form containing relational database tables as drop down It throws error

<select>
<option value=""> Select Category</option>
{%  for category in category %}
<option value="{{category.category}}"> {{category.category}}    </option>      
{% endfor %}
</select>

While inserting the data's the error is

An exception occurred while executing 'INSERT INTO new_product (product_code, product_name, quantity, price, gst, hsn_code, product_metric, product_dimension, supplier_name, category_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["RE45", "Shirt", 4, 456.9, 70.8, 2345, 3, 4, "sakthi", null]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'category_id' cannot be null

1

1 Answers

0
votes

Add these lines in Entity

public function __toString()
{
       return (string) $this->getCategory();
 }

In twig

TABLE HEADER

<th><h4>  category          </h4></th>

TABLE DATA

{%  for newproduct in newproduct %}
 <td> {{ newproduct.getCategory() }}</td>  //newproduct is another entity contains category entity as relatinal database 
{% endfor %}