0

I'm working on a project where we use views to create a interface/layer between another system which is a datasource but have no matching model. This way, in my system, these views are in fact models. Everything is working perfectly fine until now, except for this part:

-------------------------------
|Table    |Table        |View |
-------------------------------
|Order  > |OrderItem  > |Item |
-------------------------------

Relation: Order (has many)> OrderItem (has many)> Item.

I recently faced a problem where it tries to save the entire set of relations of a table (the order). The system is supposed to save the order and its items (order-items). But somehow the save ends up hiting an update on the item model which is a view and returns this error, obviously:

Code:

$order->save();

Error:

Data manipulation operation not legal on this view : UPDATE ITEM (...)

Is there a way to track this, forcing it to not occur, or set it as a read only model?

CesarScur
  • 84
  • 7
  • Hi CesarScur. It is quite difficult to comprehend your problem. Could you maybe add some sample code? Also is this PHP? Then perhaps tag it as PHP as it is a more popular tag -- to get more attention. – Czar Pino Mar 06 '13 at 15:52
  • Added the tags, TY. How can I make the thing more clear? – CesarScur Mar 06 '13 at 16:24

1 Answers1

1

This error occurs in mysql when the view is composed of elements from different tables.

If you edit columns from the same table it's ok but if the same query tries to edit columns for different tables you have an ERROR.

Are you still using Doctrine 1.2? I think using views with Doctrine was tricky Link

ALso the error can come from the way you declared the relationship on the entities:

Having: Order Many-to-Many OrderItem Many-to-One Item.

You should make sure take the relationship OrderItem > Item is unidirectional and that OrderItem is the Owning side.

Jeffrey Nicholson Carré
  • 2,950
  • 1
  • 26
  • 44
  • I'm using oracle as db. I saw the doctrine_view thingy, but, in my case, the view is in fact a model. I have business rules attached to it. The use of a db view is just a way to interface the other system. I could have use a procedure to feed a regular table, but the problem would stand: **I don't want doctrine to update this table**. My description was wrong indeed, it is has many =/ – CesarScur Mar 07 '13 at 11:45
  • Ok but the error you are getting is because Doctrine is tying to edit the view i a way that is not allowed by Oracle. here is the error cause and solution : http://ora-01732.ora-code.com/. – Jeffrey Nicholson Carré Mar 07 '13 at 16:44
  • Could oyu post the process before the save()? – Jeffrey Nicholson Carré Mar 07 '13 at 16:50
  • The solution pointed by oracle is exactly what I'm looking for, a way to force doctrine not trying to update the view, cuz I'm not calling a direct item save and can't predict why this is happening. Just shouldn't over any circumstance. I can't past, cuz it's business logic and it's thousand lines long. – CesarScur Mar 07 '13 at 18:24
  • Ok, so you will have to create a methode (example:save_order()) executing a Query to manage the save. that way you know exactly what's hapening. http://stackoverflow.com/questions/10961743/symfony-1-4-improve-doctrine-save-method – Jeffrey Nicholson Carré Mar 07 '13 at 18:45
  • This is not an option due to the extension of the program. Thousands of lines, and dozens of rules to rewrite – CesarScur Mar 07 '13 at 19:02