[ANN] Association Extensions plugin

Another plugin. This one adds a few methods to/for associations. See
below for the README. The intention is that with these methods it
becomes very easy to build collection_selects

<%= collection_select ‘person’, ‘continent_id’,
@person.continent_candidates, ‘id’, ‘name’ %>

Homepage:
http://rubyforge.org/projects/assocext/

Repository:
svn://rubyforge.org/var/svn/assocext/association_extensions/trunk

I’m looking forward to your comments. Please keep in mind that this code
needs some more serious testing as I’m sure the current tests don’t
cover all relevant cases.

Michael

Association Extensions

Version 0.1, 2006-08-28

This plugin adds a few methods to classes having associations
and to association proxies.

  • association_candidates
  • association.candidates
  • association_complement
  • association.complement
  • association_unrelated
  • association.unrelated
  • association_singular_ids

The standard method association_singular_ids= is changed so that it is
more lenient; now it ignores blank ids.

Methods on association proxies, e.g., association.candidates, can’t be
reliably called on belongs_to and has_one associations. When
associations
of these kinds are nil, there is no proxy and thus nothing to call
#candidates et al. on. The methods on the base object can always be
savely called.

== Status

The plugin is not ready for production use. Although there is a fair
number of tests, I’m not sure whether they cover all relevant cases.
In particular, I haven’t checked how the additional methods interact
with scoping.

== Limitations

  • complement and unrelated don’t work as expected when unsaved
    objects are involved. Only objects existing in the database
    are taken into account.
  • Polymorphic associations are not supported.

= Testing

The extensions introduced in this plugin need to reach deeply into
how association are implementated in ActiveRecord. Therefore, when
ActiveRecord changes, there is a chance that these extensions break.
In order to make sure that they work with the Rails version you are
using, it is a good idea to run the included tests. You can do so
with

rake test:plugins

This command runs the tests of all plugins installed in vendor/plugins.
In case the command fails without producing any sensible results for
this plugin, you can try to run only the tests specific to it with

testrb
vendor/plugins/association_extensions/test/association_extensions_test.rb

Copyright (c) 2006, Michael S., [email protected]


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/