I have something similar to this:
class Bucket < ActiveRecord::Base
serialize :droplets, Array #of IDs
end
class Droplet < ActiveRecord::Base
#...
end
Since a single Droplet can belong to multiple Buckets (the real problem is a bit more complex), is there a “rails-way” of achieving something similar to the following:
#in some action
@bucket = Bucket.find(47)
@droplets = Droplet.find_all_by_id(@bucket.droplets)
so that one can access Bucket#droplets where every element of the array would be a Droplet?
It sounds like you want a many to many relationship.
It is really recommended to do this with 3 tables.
if you dont want this, you have to keep the array in the sql, in which case you will lose some rails functionality and have to do it as you described yourself with
if you want to do in a cleaner way do:
you will need a migration: