-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Aug 5, 2006, at 4:26 PM, Jeremy Kemper wrote:
-----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?
Currently it's baked into a mixin that decorates the behavior onto
models I need to generate the queries with. Should just be a matter
of factoring out into a patch and recreating the appropriate tests.
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.
Great, I'll look at this as I make the patch.
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.
No problem, I'll merge Postgres on one of my boxes and give her a whirl.
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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iD8DBQFE1SV1qvuZB2zXNU0RAh23AJ4hCw8z0NfFfeoB6kPpqazgNcYeAACeIQO1
VL9ht4ruy4hHaeiMLsCulO8=
=Clny
-----END PGP SIGNATURE-----
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core