问题
Apparently, a lot of ORMs do something like this:
query.filter(username == "bob")
to generate SQL like
... WHERE username = 'bob'
Why override the == operator instead of something like:
query.filter(username.eq("bob"))
回答1:
This is a subjective question, but in general I would say that the syntax for the former is more intuitive, and since many (if not most) ORM's do this it's generally expected (making it more intuitive).
回答2:
The whole point of orm is brideing the "impedance mismatch" between object and relational world , So in theory you can be blissfully unaware of "=" in sql world and work with "==" of the object world.
来源:https://stackoverflow.com/questions/1185537/what-advantage-is-there-to-overriding-the-operator-in-an-orm