说我有一个Foo模型。一个Foohas_many Bar。Bar商店value。AFoo将多个Bar对象存储为一个combo对象。
例如:
f = Foo.find(2)
f.combo
# combo is essentially Bar.find_by(foo: f).pluck(:value).join(" ")
# I want to be able to easily retrieve (like above)
# create/edit/update
f.combo = "moo cow"
# all related existing Bar objects should be updated,
# and new additions should be created,
# and no longer relevant ones should be deleted
f.save
# delete
f.combo = nil
# all related Bar objects should be deleted
f.save
有没有一种方法可以轻松地完成上述逻辑?