- Add support for extensions on
has_manyandhas_and_belongs_to_manyassociations in Rails 5.0 and above
- The arguments of
#where_assoc_countcan now be swapped when comparing to a number or a range.
Sowhere_assoc_count(:posts, :>, 5)is now valid for having more than 5 posts.
- Optimize
has_onehandling for#where_assoc_existswith ahas_oneas last association + without any conditions or offset. - Optimize
has_onehandling when the foreign_key has a unique index and there is no offset
- Add support for composite primary keys in Rails 7.2
- Add compatibility for Rails 7.2
- Add compatibility for Rails 7.1
- Add support for associations defined on abstract models
- Add compatibility for Rails 6.1
- Fix handling for ActiveRecord's NullRelation (MyModel.none) in block and association's conditions.
- Added methods which return the SQL used by this gem:
assoc_exists_sql,assoc_not_exists_sql,compare_assoc_count_sql,only_assoc_count_sqlDocumentation for them
- Fix broken urls in error messages
- Now supports polymorphic belongs_to
- Use
SELECT 1instead ofSELECT 0... ... it just seems more natural that way. - Bugfixes
- It is now possible to pass a
Rangeas first argument to#where_assoc_count. Ex: Users that have between 10 and 20 postsUser.where_assoc_count(10..20, :==, :posts)The operator in that case must be either :== or :!=. This will useBETWEENandNOT BETWEEN. Ranges that exclude the last value, i.e.5...10, are also supported, resulting inBETWEEN 5 and 9. Ranges with infinities are also supported.