Pergunta

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.

Foi útil?

Solução

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 ?

Outras dicas

embed_key is even better

has_many :task_observer, embed: :ids, embed_key: :custom_id_field_name
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top