Auto_complete – create association to anot her model – handle foreign-keys - validation

Hello,

In the app that I’m currently developing I want to use the
auto_complete plugin to create an association from the model “ticket”
to the model “customer”. In the new ticket form I created the field
“customer name” as an auto_complete field. The controller handles the
lookup on the name field of the customer model.

As I retrieve the name of the customer in the new ticket form this
parameter is passed to the create action in the ticket controller when
I hit the create button. In the controller I lookup the name of the
customer and create the association from the ticket model to the
customer model in that way.

This works fine for the moment as the name of the customer is unique.
But what happens when the name of the customer is not unique? How can
the controller know which customer to associate the model to when
there are two costumers with the same name?

In my opinion it would be a better solution to retrieve the
customer.id beside the customer.name. Doing that would it make
unnecessary to lookup the customer in the controller as the desired id
of the customer is included in the params hash.

Thinking a bit further I’m also wondering how to make validation work
on the customer field.

Is there a common solution to that problem? Does anyone have an idea?

Thanks
Marc