-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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). 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

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
4) Documentation. Update the doc blocks to include the key and document in the patch ticket? 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. 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?

Anyway, pointers are appreciated. I have this already working in my limited world, hopefully it can grow up and be useful to the larger community...

Cheers,
Blake
- --
Blake Watters
Near-Time, Inc.
http://www.near-time.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iD8DBQFE1Dh7qvuZB2zXNU0RAsUoAKCxSUySagoi1kMMoVLpJs7qEsvMmgCfdEE4
O3Xx14CilzCDaCcNhFVnf4g=
=I6St
-----END PGP SIGNATURE-----
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to