Difference between #1 and #2 of
When to use Active Record

Revision #2 has been created by samdark on May 23, 2020, 7:32:04 AM with the memo:

Fix typo
« previous (#1)

Changes

Title unchanged

When to use Active Record

Category unchanged

FAQs

Yii version unchanged

all

Tags changed

active record

Content changed

[...]
> I have about 500K records in my DB tables and each query there are 2 or 3 joins. I was getting data via AR, about a hundred records a time and noticed that using `createCommand` consumes less memory and CPU. I think with DAO instead of AR it will be faster.

It is true that Active Record consumes memory for storing objects and CPU cycles for instantiate these objects.

> Is AR bad? I
ts it for small projects only? We have lots of inserts, about 5000 records an hour and we're using AR for that. Should we re-write?

AR is a pleasure to use when you're managing not that many records at the same time. CRUD is very easy with it. Yii 2 dirty attribute support (only what was modified is saved) off-loads database and mitigates many parallel editing conflicts. If you don't have complex logic in your app and you don't need entity abstractions, AR is an ideal choice.

AR is OK for queries not too complicated when they return no more than a hundred objects. Yes, it is faster and less memory consuming to use query builder or `asArray()` but working with arrays is significantly less convenient.
[...]
13 0
4 followers
Viewed: 52 644 times
Version: all
Category: FAQs
Written by: samdark
Last updated by: samdark
Created on: Aug 9, 2018
Last updated: 3 years ago
Update Article

Revisions

View all history