mercredi 21 octobre 2015

Two models to store in database as one transaction

I have two models Item and ItemDetail and they have a one-to-many relationship

One-to-many because I store the item details as Entity–attribute–value Table, it is nothing but a table the columns and label and value that stores ItemDetails as following

id|item_id_fkey|Label         |Value
1 |1           |Color         |Black
2 |1           |Description   |Item 1 Details
3 |1           |Size          |2x4x6
4 |2           |Description   |Item 2 Details
5 |2           |Weight        |1000

When I create an Item it ask me Item->name and Item->Price, on Submit it calls the ItemsController@store and redirect to ItemDetailController@create with newly created item id.

ItemDetailsController@create redirects to a Form with lot more fields to for gathering item details (e.g. ItemDetail->Description, ItemDetail->Dimensions etc), and on submit it stores the ItemDetails model.

Problem:(Not as complex as the situation), The issue is I want it to be such that if user creates item in first form and does not update the item details in second form, item shouldn't present in Item table as well. In another words two store methods should be one single transaction.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire