Вопрос

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