Skip to content

How should we be using Models & Records? #10063

Answered by brandonkelly
Mosnar asked this question in Q&A
Discussion options

You must be logged in to vote

There’s nothing inherently wrong with using ActiveRecord, and it’s not something I feel super strongly about one way or the other. But we have avoided it for a few reasons:

  • They come with a memory & performance hit, compared to using normal DB queries and populating a model with predefined properties. Not as bad in Craft 3 thanks to schema caching and better code, but still a factor.
  • There is a 1:1 mapping of record attributes and DB table columns, which isn’t always ideal. Some models (particularly elements) have properties whose data span across multiple DB tables. Even in cases where the 1:1 mapping is fine, you might want to work with it in a different format than its stored (e.g. a D…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants