New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return and instance of Arel::Attributes when calling []
on the model.
#264
Conversation
So, now you can do something like this: Topic.where(Topic[:ratings].gt(5)) Without having to call `#arel_table` first.
+1 |
I've used it too +1 re https://twitter.com/#!/tenderlove/status/57839406987493376 |
+so many. I use arel_table constantly. It feels clumsy having to type it everywhere. (re https://twitter.com/#!/tenderlove/status/57839406987493376) |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Agreed; This is a good idea. I use arel_table an awful lot in order to access predicates, and I find it rather clumsy to have to assign it first. |
+1 idem as @scottlowe |
Like this really, +1 (re: https://twitter.com/#!/tenderlove/status/57839406987493376) |
+1 re https://twitter.com/#!/tenderlove/status/57839406987493376 (with other folks doing slighlty longer relation.table), using for things like |
Neat! |
+1 |
1 similar comment
+1 |
-1, using the class twice does not sound good enough. |
+1 |
Just to throw an idea out there. If it's a DSL, make it a DSL:
or is that too much magic? :) |
+1 awesome! |
Definitely +1. Makes not-writing SQL more attractive, which is a win for the universe. |
You guys have no sense of what this kind of syntax would do to people new to Ruby. Fit's of despair would probably be a mild side effect. Don't forget, we are not trying to turn Ruby into a gulfing complete version of Perl, we are trying to create a framework which aids in Ruby's main mission of providing syntax that makes sense to people and just incidentally happens to be machine executable. .gt is broderline but something like fame.gt(100) & awesome? is just ridiculous. in any case -1 from me. |
famous_users = User.where(User[:fame].gt(80)) Real nice, but repeating User is just WRONG, unless I can do that: famous_users = User.where(Posts[:age].gt(80)) |
My opinion this DSL should be in core: https://github.com/ernie/meta_where So much more natural than the one suggested. Would never use the proposed syntax myself, just feels wrong/bloated. |
tobi > I totally disagree. I just asked 3 people who have any idea in what is even ruby (not a jewel) : "what means for you fame.gt(100) & awesome, knowing that gt means greater than". They all answered me "fame superior to 100 and awesome ?". So I don't think it's a problem, I think the DSL idea makes sense. And yeah. meta_where is just amazing. |
I'm inclined to agree with @grimen - the syntax just seems off and meta_where is something I frequently use. I'm not looking forward to explaining the difference between user.attributes[:first_name] and User[:first_name] to newcomers. I like the idea/concept, but I don't think the DSL is quite right yet. |
Thanks for the MetaWhere love but I wouldn't advocate the existing MW go into core, and I wrote it. Squeel (formerly MW 2.0) plays more nicely with others and the syntax is much improved, as well. It's still a work in progress but I hope to have it wrapped up by RailsConf. |
Why not use the Mongoid-style syntax? User.where(:fame.gt => 80, :awesome => true) Edit: Never mind, I see that's what meta_where does too. |
By way of example, Squeel DSL:
|
ZOMG, -Infinite then. |
Hi,
I've discussed with Aaron a while ago about the way that I can use ARel's comparison methods (
#gt
,#lt
, and so on) in AR. Turned out that I have to access it via#arel_table
method of the model:This become a bit tedious as I have to have another variable to store an instance of
Arel::Table
to be able to call those methods on it. Also, I don't think the code look clean if I merge those two lines together and make it asSo, after some discussion, I think it's better to make AR
.[]
method to return the instance ofArel::Attributes::*
. This will give more readability to the code example above, and I think it fits in great with the context.After applying my patch, you would then can do
I think that looks really nice. I really wish I could get some feedback from you guys.