I have many-to-many relationship (HABTM) in a file service:
class Album < ActiveRecord::Base
has_and_belongs_to_many :media, join_table: 'albums_media'
end
class Medium < ActiveRecord::Base
has_and_belongs_to_many :albums, join_table: 'albums_media'
end
We have a gem containing the ActiveResource interface classes into that service:
class Medium < ActiveResource::Base
...
def albums
Album.where(id: album_ids)
end
end
I can easily create a Medium that belongs to a given Album by passing album_ids
:
album = Album.create(...)
medium = Medium.create(album_ids: [album.id])
I'd like to be able to delete a certain medium
from a given album
, but ActiveResource doesn't really support this directly.
# not supported...
medium.albums.destroy(...)
And I'd rather not use has_many :through
as I don't really need to manage the join directly other than doing this kind of thing.
Any insight is appreciated.