On Sunday, 3 June 2012 at 5:05 AM, Bruce Perens wrote:
Hi,I have a complex query that, as far as I can tell, either requiresArel or SQL. Performing Arel queries with ActiveRecord is awkward.Getting the query into ActiveRecord requiresproject(node_table.columns)and thenfind_by_sql(query.to_sql)There should be a method of ActiveRecord that accepts an Arel query,does the appropriate projection, and executes the query. ConvertingArel queries to SQL defeats the purpose of Arel. Arel should not bedependent on SQL and should be able to work on no-SQL databases.
Core to this issue is the ActiveRelation vs. Arel dichotomy.ActiveRelation is Arel's poor cousin that can't measure up to it. It'san easier interface as long as your main query is where(field: value),but doesn't provide all of the functionality of Arel.
Arel was one of the most promoted features of rails 3.
Perhaps this wasn't your intent, but it's so. In contrast, these are the only methods of ActiveRecord::QueryMethods with a word of documentation on api.rubyonrails.org: extending, reorder, select, uniq. Even where has no documentation. joins() is similarly undocumented. And when one figures out ActiveRecord::QueryMethods, it's only to find that many of the methods require SQL fragments as arguments and aren't particularly portable across databases. If you look around the net for help on doing complex queries with Rails 3, the instructions are to drop into Arel and then feed it back to ActiveRecord.
With all due respect, you seem to have a disconnect with your users.
At some point (I don't know when) it was decided that rather than constructing SQL out of string fragments, Rails 3 would use Arel to build SQL but with a separate query interface that maintained backwards compatibility but added functionality (ActiveRecord::Relation). However because Arel was already quite well known by that point some people got the wrong end of the stick, especially with the protracted development of Rails 3.
...
So, what is our recommended path for users once they are writing those 20% of queries that Active Record Querying operators aren't designed to cover? You can expect them to have to do so at least once in every large application.
Sequel looks interesting. At first glance, it looks more mature than AR, and I guess shows how AR might evolve. Of course, I know nothing about its performance, etc. I might try it in my next application.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/Dcgs-Xq1guMJ.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Lack of documentation, support, and a good-enough API. All of that I've found in Sequel and it further performed better than AR, so yay! ;)
Pretty happy with the move and I sincerely wish the best of luck for AR to get over the "80%" it currently supports...
Squeel (not to be confused with Sequel) does a pretty good job of covering the other 20%.
Il giorno 04/giu/2012, alle ore 23.27, Bruce Perens ha scritto:
Sequel looks interesting. At first glance, it looks more mature than AR, and I guess shows how AR might evolve. Of course, I know nothing about its performance, etc. I might try it in my next application.
Yes, AR might evolve. Sequel has intrigued me as well, but relying on unofficial solutions scares me a little, even if it has a good support.
Sorry, but I have no idea what you're talking about. Could you please give me an example of one of those AR plugins you're referring to?
Em 05-06-2012 00:17, Maurizio Casimirri escreveu:
Sorry, but I have no idea what you're talking about. Could you please give me an example of one of those AR plugins you're referring to?
Sorry, you are right i was referring to gems that involve querying the database through AR, Devise to say one that yourself mentioned.
As in a past thread in which we discussed together, in brief my thought is: there are probably some good reasons that prevent rails to drop ActiveRecord, but with a well thought and well designed interface the fact that ActiveRecord is the default for rails would not seal the giant support AR has to the other ORMs or persistence solutions.
The situation with Sequel is probably similar to what i faced once with mongoid. At first glance all seemed good to me, but then i realized i was spending a lot of time on the framework (patching something, choosing alternative gems working with mongoid ...) more that on my business (and I probably liked this as i 'm writing here now ;) )
I think that this is a case in which a bit more of engineering would not hurt.
I guess I got what you mean, although I don't agree.
Rails 3 is a pretty solid and modular framework in my opinion, lacking just a decent documentation.
It doesn't rely on AR for anything. It is just included by default but if you run "rails new app -O" then AR won't be included as a dependency (although installing rails will also install AR, which seems wrong to me as AR shouldn't be a dependency for Rails).
But you can't just define a common API that all gems will be able to use regardless of which ORM solution you chose. The ORMs can take very different approaches when dealing with API design and that is what make them so interesting.
The problem relies in the gems in my opinion. They should follow the SRP instead of just assuming things to get a broader range of users.
Even if there are any interface "keyword" in Ruby, you can still write interfaces in a number of ways.
The easiest one would be to document what methods you expect from the ORM for it to work and how they should respond.
An even better approach would be to provide a test-suite that all conforming adapters would pass when correctly implemented.
So, this time I think Rails is currently very well designed and I'd like to thank a lot Yehuda, José Valim, Piotr Sarnacki and all core developers for the excelent job they did on making Rails more modular and easy to extend with Engines. A lot of unnecessary dependency was cut off and Rails just doesn't seem to be the issue anymore for adopting alternative solutions like testing framework, orm and JavaScript library. This was really a great engineering design and the Rails community should be proud of their code base.
Educating gem authors to follow Rails' example should be much easier and less painful.
Il giorno 05/giu/2012, alle ore 13.55, Rodrigo Rosenfeld Rosas ha scritto:
...
Em 05-06-2012 00:17, Maurizio Casimirri escreveu:The problem relies in the gems in my opinion. They should follow the SRP instead of just assuming things to get a broader range of users.
You are right, but you can say now that all the gem creators take this into account?
Even if there are any interface "keyword" in Ruby, you can still write interfaces in a number of ways.
You are right again, i'm not saying that the missing of an interface keyword is a problem by itself but i'm concerned to the fact that due to this many times ruby libraries expose the implementation to the client code (eg. we need to call #arel_table).
Also and probably more often, libraries API will change when implementation changes.
...
So, this time I think Rails is currently very well designed and I'd like to thank a lot Yehuda, José Valim, Piotr Sarnacki and all core developers for the excelent job they did on making Rails more modular and easy to extend with Engines. A lot of unnecessary dependency was cut off and Rails just doesn't seem to be the issue anymore for adopting alternative solutions like testing framework, orm and JavaScript library. This was really a great engineering design and the Rails community should be proud of their code base.
Educating gem authors to follow Rails' example should be much easier and less painful.
Well here i see a misunderstanding i don't think that Rails has a bad design but that it can move to an approach that is a bit more friendly to enterprise applications where it doesn't make things too complicated in order to make our applications more maintainable and age resistant.
Probably i need to cite someone that is better than me: http://www.languageparallax.com/wordpress/?p=39
I had the feeling that a more enterprise-oriented approach can be achieved in rails when i looked at play framework, (even if the current version is a nearly unusable mess due to its young age) it proves that there are ways to fill the gap between enterprise requirements and simplicity and quickness belonging to agile frameworks like rails.
I'know that you don't like it but sometimes i prefer data mapper and domain driven design over active record and database driven design, the same way i would like to see a two-step view approach for views.
If for the latter there are no problems (i can quickly implement it with a few lines of code and only my views will depend on it) for the first one i've a lot of trouble due to the lack of solid support, since i don't think that rails will drop AR my proposal is to have at least a complete querying/mapping interface that can bridge the gap from ORMs.
In any case i will look at Sequel, now i'm too curious! ;)