Answer the question
In order to leave comments, you need to log in
Whether there is a sense to study, write on ActiveRecord?
Started learning frameworks.
I was the first to take Yii2, tell me please, is there any point in ActiveRecord ... does anyone really use it?
At first I thought that this is a very cool thing that simplifies life.
But when I get to Join and complex queries, some kind of hell begins (
Still a student, is there any point in this AR, from the point of view of employment?
Answer the question
In order to leave comments, you need to log in
This is a very controversial thing. It can be used on simple queries, but if it comes to normal selections, then AR is aside and only native sql.
does anyone really use it?
Well, if it were my will, I would throw out all the constructors and write to $connection-> createCommand
You are confusing ActiveRecord with QueryBuilder. AR is a design pattern that implements data access.
Complex queries can be written using pure SQL and using AR, for example from the docks:
// returns all inactive customers
$sql = 'SELECT * FROM customer WHERE status=:status';
$customers = Customer::findBySql($sql, [':status' => Customer::STATUS_INACTIVE])->all();
Well, if it were my will, I would throw out all the constructors and write to $connection->createCommand. I'm
just interested in questions from the point of view of the subsequent interview and teamwork, as a junior
. As for me, 2 lines of a native query are more convenient to read than 10 lines of a constructor.
I'm just interested in the moment, will they be beaten on the hands for not using AR?
Queries like this:
select * from products
LEFT JOIN products_categories ON products.id = products_categories.id_products
LEFT JOIN categories ON products_categories.id_categories = categories.id
Is this considered a complex query?
It’s just that I’ll write this in 10 seconds, and on AR it’s 10 times further to design.
AR speeds up development.
for example, you have a complex system, well, let it be the sale of cars, in which the site, api for mobile platforms, some other crap.
You choose them (cars) in dozens of places.
And then the task comes to you: add the "spam" flag to the machines and ignore everything marked with this flag in all-all-all select requests.
On the native, you will add this condition in dozens of places.
in AR you will fix one place...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question