-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Aug 4, 2006, at 11:19 PM, Blake Watters wrote:
I have recently needed support for having clauses for some advanced
find queries in my application. I've implemented this in a mixin
that implements a new set of finders and query constructors that
mirror the core Active Record, except for the additional support
for :having as an argument. This has reached stability and now
works with eager loading and scopings, so I'd like to extract it
from my application as a patch against Active Record core.
I thought I would talk this through before producing a patch and
missing the mark and having to refine, so a few questions:
1) Can I confirm that :having feels like core functionality? I see
that it is part of the calculation module already, but I need it to
restrict my find results set and not just perform counts and so
forth. Basically I am performing a join and want to use :having to
check that the joined results match a threshold (i.e. HAVING count
(visits.id) > 0).
Sounds good, Blake. Do have a patch, or is it tied into your app?
2) I have identified the following places where :having needs to be
added:
associations.rb - construct_finder_sql_with_included_associations
base.rb - construct_finder_sql
base.rb - validate_find_options
construct_finder_sql + :having is enough to support Calculations too,
so we can DRY out its duplicate sql construction.
Anywhere else that I am missing?
3) I believe the following tests to be necessary for a good patch,
what am I missing?
- vanilla find with having, single table
- find with having, with join tables. Having against base table
- find with having, with join tables. Having against join table
- find with having, using scope
- find with having, using eager loading
+ behavior in nested scopes
4) Documentation. Update the doc blocks to include the key and
document in the patch ticket?
Yes, please.
5) Errors. Do I need to provide any validation on the arguments or
new errors or can I just let AR blow up with exceptions if you ask
for a boneheaded query? The group clauses here become very important.
You can just let the db raise exceptions as usual.
6) I develop on MySQL exclusively. What kind of cross database
problems do I need to consider? (i.e. I haven't researched that
having clauses will work everywhere). Is there a database specific
element to what I am trying to accomplish?
Please give PostgreSQL a shot. If it works there, it's likely to work
elsewhere.
Thanks!
jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iD8DBQFE1P8AAQHALep9HFYRArNaAKC+/XtvYvBJVaTTCxxTxnPh208CxgCgxGmA
6L2i1CzUeh+jP1s7z9GTA+Y=
=wp+t
-----END PGP SIGNATURE-----
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core