Last year I implemented array association on my GEM exclusively for PostgreSQL:
I’m planning to push this feature to Active Record, so any database that supports array could use.
The main steps that I took was:
Identify array associations with something like
Create a generic method that infers the correct way to connect both keys (primary_key and foreign_key), instead of direct use of
castto be called on Some Arel Nodes
Make sure that
AssociationScoperely on the above generic method to build the condition
Create the correct
BindParamfor each value on an array association
Create the necessary
AutosaveAssociationto behave properly against array associations
A couple of other minors adjusts to make it seamless to other associations
The only problem so far is that it doesn’t work with Polymorphic, but, it’s so far a big win, especially for systems with
conversations (with multiple users).
I was thinking about pushing it to Rails not only because it’s a cool and handy feature, but also because one of the problems that I faced recently with the GEM, where the
eq condition is hardcoded, and that annoys me since it could open a door for many other customized associations. Here are the commit and line that got me thinking about this:
I want to hear people’s opinions. And, if I decided to move forward, I’ll do one step at a time, probably starting by the generic method on step #3.