3 ms·
Come on - how hard is it to write "select id, username, email, nickname, date_registered, pass_hash, first_name, last_name, middle_initial, home_phone, mobile_
by mgkimsal 14y ago
Come on - how hard is it to write
"select id, username, email, nickname, date_registered, pass_hash, first_name, last_name, middle_initial, home_phone, mobile_phone, work_phone from user where username=?" and manually do escaping whenever you want user info?
You seem to be suggesting that
user.findByUsername('joe')
is somehow more worthwhile or usable. It's certainly more noble, because an ORM doesn't solve 100% of a set of problems 100% of the time. OBVIOUSLY it's better to never use them, ever. In any circumstance.
"select id, username, email, nickname, date_registered, pass_hash, first_name, last_name, middle_initial, home_phone, mobile_phone, work_phone from user where username=?"
is really more readable because I always want to know every single piece of data, and read it every time I look at code (and update all my SQL queries every time I make a schema change) all the time. I'm finding that my monitor is often devoid of code - I have too much space on the screen just begging to be filled up with useful boilerplate code so I don't ever forget all the column names in every table.
- krig 14y agoYou pretty much nailed what I was going to say. Yeah, I found it a bit strange that the only alternative to using an ORM that the author could imagine was to roll your own? What's the problem with using SQL directly? To answer the grandparent: I did read TFA, and I don't buy it. His claim that a good ORM makes 90% easier and gets out of the way of the remaining 10% doesn't match my experience with any ORM at least. Perhaps I'm wrong! All I'm saying is that from what I can tell, using an ORM buys you nothing worth buying. edit: Ha, you're being sarcastic. No, I'm serious. Are you saying that using an ORM solves escaping problems? I honestly have never connected those two. That to me is a problem calling for a set of escaping/unescaping functions, not an object-relational mapping. To each their own...
- zzzeek 14y agocopying my answer from virtually the identical commentary made on reddit ("why should I use an ORM when I can just write the SQL?") (not to mention Fowler's article makes this same point pretty clearly): ORMs do not claim to be "simpler than SQL" and this has nothing to do with the purpose of an ORM. There is nothing that's ultimately "simpler than SQL", if in fact you aim to just write SQL. The purpose of the ORM is to marshal data between an object-oriented domain model and a relational schema, to translate a wide array of common relational patterns with corresponding domain-model patterns (think foreign key to collections, for example), and to express relational queries in terms of the object model at least to some degree. All of this is well outside the realm of just "writing SQL queries". The ORM is a tool used to integrate relational databases with an object oriented application layer, and to that degree they make this task a lot less effort than doing it by hand.