A practical guide to deciding when Yii 2.x ActiveRecord or Query Builder is the right tool for complex queries, with a worked example, performance trade‑offs, and a profiling checklist.
A step‑by‑step diagnostic guide for ActiveRecord connection‑pool exhaustion in Rails, covering symptoms, causes, checks, fixes, and when to involve a DBA.
Scopes work best as small, reusable constraints. Keep final query assembly at the call site, and verify the generated SQL with to_sql before trusting a long chain.
Choose has_many :through when your many-to-many relationship carries data or behavior—like appointment dates, statuses, or notifications. The join model becomes a first-class Active Record object with validations, callbacks, and scopes, keeping domain logic where it belongs.
Stop writing repetitive CRUD boilerplate. Learn how to use Yii's Gii code generator to automate Model and Controller creation while avoiding common security pitfalls.
Yii's with() and joinWith() both solve N+1 queries but generate different SQL. with() uses separate IN queries and preserves pagination; joinWith() uses JOINs but multiplies rows for hasMany relations. Choose based on relation type, pagination needs, and column filtering requirements.
Learn how to leverage Yii's Gii generator and ActiveRecord for rapid prototyping while avoiding common performance pitfalls like the N+1 query problem.