3 ms·
This is a psychological problem not a technical one. If you've already written the SQL the right choice is to use that and not translate it into the ORM. The
by wvenable 10y ago
This is a psychological problem not a technical one. If you've already written the SQL the right choice is to use that and not translate it into the ORM. The other way is madness, which you know, but you don't accept it.
An ORM is supposed to save you time. And it does. For the bulk of database interaction an ORM will save you a lot of effort. But it's not the be-all-end-all. It has limitations. And when you hit those limitations, you just don't use it. This isn't a huge strike against ORMs in general because every technical choice is a trade off. You just have to accept that it is a trade off. And because it's a trade off, sometimes it'll be the wrong choice for a task.
I've been in your situation and I happily add the SQL to the model directly and go back to my day. I don't worry that I didn't use the ORM. It's there to help me, not hurt me.
- iamleppert 10y agoI guess I'm just not sure exactly what, save for trivial queries the ORM is actually good at abstracting? We can all write simple queries with simple joins (I hope), that doesn't really save much time. In my experience anything more than a trivial model with a boiler-plate relation it becomes not worth it...
- wvenable 10y agoORMs are good for manipulating complex object models and doing mostly trivial queries. However, the vast majority of queries are trivial. Maybe 2-5% of queries or bulk modifications can't be easily modeled. The result is still huge savings in time, effort, and code. Also, if you're basing your entire understanding of ORMs on ActiveRecord, you're missing out on a lot.