3 ms·
Most of the relationships are belongs_to and has_many. How is a raw SQL more readable and expressive than that? Sure, there may be an occasional AR expression
by aantix 7y ago
Most of the relationships are belongs_to and has_many.
How is a raw SQL more readable and expressive than that?
Sure, there may be an occasional AR expression that could be optimized with a raw SQL query?
But for most associations for information based systems, AR is incredibly descriptive and performant.
- ratww 7y agoActiveRecord is far from straightforward when it comes to joins, unfortunately. Even if you use belongs_to/has_many you still have to manually perform the join, otherwise you'll get an N+1 issue which will affect your performance. On top of that there are four ways to perform that join: joins(:table), include(:table), eager_load(:table) or preload(:table). In SQL you can basically achieve the same level of expressiveness by using NATURAL JOIN.
- aikah 7y agoMost SQL databases now support returning rows in the form of JSON allowing N,N+1 queries to be fetched in a single call, so it's easier to deal with many to many relationships in SQL directly without an ORM. Query builders are still useful though.