This project is archived and is in readonly mode.
Pluralized AR models (think Posts.find(:all) instead of Post.find(:all))
-
Yaroslav Markin
Forgot the patch
-
Yaroslav Markin
patch cleanup, sorry
-
Frederick Cheung
What's the motivation for this? Seems to me like quite a lot of magic just to make some code read more like English (which I think is something of a false idol)
-
DHH
I must admit that I've wanted this since forever, but I'm not sure if we should go there. Let's get some opinions on where it might provide trouble.
But I still to this day write Posts.all in the console. Which is an indicator to me that my brain doesn't want to concede collection operations on a singular class ;)
-
Josh Susser
-1
This change needlessly pollutes the constant namespace, and offers no increased functionality. It's nothing but sugar with no nutritional value. And it comes at a potentially high cost of complicating both the class-loading code and muddying a rather simple set of conventions. It's likely also to play havoc with the set of emerging Ruby IDEs and their ability to locate class definitions in files.
-
Yaroslav Markin
Josh, how do you think, is there any way this functionality can be done in a more simple way without complicating stuff? Please share any ideas. Can't really think of one..
It sure complicates class loading a bit and adds class proxies just for cool syntax, but the ability to call finders on plural class is something I'd love to have.
-
Josh Susser
I don't have any ideas on how to simplify this, but I'm not really motivated to do so. I think this is a bad idea, and enabling sloppy coding doesn't seem like a good reason to add complication.
-
Frederick Cheung
Also the code does not quite honour the promise not to clobber an existing Posts class: it does indeed check defined?(Posts) but the posts class may simply not be loaded yet.
-
Yaroslav Markin
Frederick, you are right, thanks for noticing this.
-
Xavier Noria
Mixed feelings as well.
Also, I often write Posts.all. That kind of suggests there's something into this feature. But on the other hand models are singular by convention and Post.all is plain Ruby I should have no problem with.
Smells to me like adding too much stuff to the namespace.
I am +0 on this one :-).
-
Yaroslav Markin
The patch is probably going down, still I tried to solve issues that Frederick pointed to.
-
Yaroslav Markin
The patch is probably going down, still I tried to solve issues that Frederick pointed to.
-
DHH
- State changed from new to wontfix
Yeah, I don't see this making it in either. But I want to commend you for the effort :D. You could definitely turn it into a plugin, though.
-
Yaroslav Markin
For the history: http://github.com/yaroslav/plura...
-
Oleg Andreev
Huh. Another, cleaner attempt is here:
The idea is to return an appropriate singular const when const_missing is called (like "Posts not found"). No constants are created.
This should work fine with the evil dependencies.rb :-), but i have not tried yet.
