I know that when embedding associations we can do the following

has_many :task_observer, embed: :objects


has_many :task_observer, embed: :ids

Is there a way to to embed a different field in the association other than the id, like contact_id or task_name as the array instead of the primary key? Please let me know.

有帮助吗?

解决方案

What if you would do something like :

attributes :task_observer_contact_ids

def task_observer_contact_ids
  object.task_observers.map(&:contact_id)
end

Is it what you're looking for ?

其他提示

embed_key is even better

has_many :task_observer, embed: :ids, embed_key: :custom_id_field_name
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top