0

Supposed I have a model Relleno(relleno_id, descripcion) with records:

(1, Activo)
(2, Inactivo)
(3, DNI)
(4, LC)
(5, LE)

Then, I want to connect 2 entities with this model: Chofer(nombre, estado) and Cliente(modelo, tipdoc), where

  • Chofer.estado can have the values 1 or 2 of Relleno.relleno_id, and
  • Cliente.tipdoc can have the values 3, 4 or 5 of Relleno.relleno_id

Since the names of the fields in the entities aren't the same (for example, in Relleno is *relleno_id* but in Chofer is estado) I am confused about how to model the corresponding migrations and associations.

Could you help me?

eKek0
  • 23,005
  • 25
  • 91
  • 119

1 Answers1

0

Rails associations involve one model referring to another via the other's primary id. There is no mechanism that I'm aware of that allows you to define associations solely in terms of non-primary-id fields as you have described here. If I've misunderstood and that is not what you're asking to do, I apologize.

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
  • Thank you for your reply. My question was wrong, read it again now please. I was talking about Relleno.code when I should be talking about Relleno.relleno_id. As it is now, the associations are based on Relleno's primary key relleno_id. – eKek0 Nov 14 '13 at 23:37
  • The primary key for `Rellono` would typically be `Relleno.id`, not `Rellono.relloni_id`. Did you really define it differently? – Peter Alfvin Nov 15 '13 at 04:25