Erik,
> Product.find(:all, :conditions => ['category.name = ?',
"Books"]) is not really LINQ
True, although it's one of LINQ's more useful features and it would
be a big step forward for Rails.
I wonder if it would be possible to create a class that essentially
creates an RPN-based log of how it was executed
Product.select { |p| p.category.name == "Book" }
So select would yield with argument p as a SqlLogger class.
- p.category would invoke log something like " push_property
'category' " and return itself (p)
- (previous_result).name would invoke the same " push_property
'name' " and return itself (p)
- "Book" would be ignored (which at first seems like a problem,
but it gets solved in the next line:)
- (previous_result).<=> would recognize that its parameter is a
string, so it would first call " push_value string " and then call "
push_comparison ". If the parameter is of type SqlLogger, then the
expression will already have been pushed on the stack so it can only
call "push_comparison". Now the problem is, how do we know whether
<, <=, ==, >=, or > was called... and we don't. But assume we can
solve this, let's continue.
So the called after select called yield, its result would be p, the
SqlLogger which now has an RPN-based execution log, which could then
be used to generate the SQL.
After writing all this, I realize that you probably went through the
exact same thing (but in more detail) when writing your class, and
there might not be a solution for if/unless/== etc. Maybe the non-
integrated string parsing is a better solution because there would be
fewer subtleties.
- Mike