I’m trying to use an array column to crete an association between 2 models. I remember that in the past this was working, but I think something has changed and now it’s not working anymore. Here is the deal:
class Group < ApplicationRecord
has_many :users, primary_key: :user_ids, foreign_key: :id
end
``
And the oddest thing about this is that the following works fine:
Group.first.users
``
It gives me the list of the users with the ids filled on that field, but the following doesn’t work:
Group.first.users.load
``
It gives me an empty list. And, since the load method doesn’t work, I cannot do any operation like #each or #to_a.
I already did some dig up, and found the source of the problem here:
The first command don’t replace the original value by a Replaceable, the second does. Maybe we just need a ReplaceableArray or something like that, or I’m missing something here.
I have seen this GEM before, but I wouldn’t recommend it, because it doesn’t use ActiveRecord Relation, which means that it probably doesn’t work with “preload”.
I’m planning to add this feature to my own PostgreSQL GEM this month, so if you are still interested in this feature, keep track of the new version here: