A
A
AvoiDFaTE2017-02-21 19:30:27
Yii
AvoiDFaTE, 2017-02-21 19:30:27

Yii2 How to save ActiveRecord via Table API stored procedure?

Advise, please, a way, if at all appropriate, how to use Active Record in conditions where the entry to the table is made through a stored procedure, and not by a direct INSERT or UPDATE statement. Those. part of the logic is performed on the side of the DBMS. So far, I see only the option of overriding the insert and update methods of the model and hardcoding calls to stored procedures in them. But this seems to me barbaric from the category of "why then AR?". Suddenly there are alternatives.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-02-22
@AvoiDFaTE

The presence of logic in the DBMS itself is not correct. So if you can avoid it, avoid it. If, however, this situation cannot be avoided (all sorts of cases happen ...), then you have two solutions:
1. If your AR does not contain special logic and queries to the database, then implement a separate repository class that will work with DB, including saving
2. If AR contains some kind of logic or queries - then only crutch and redefine saving at the AR level

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question