has_many in rails

Posted by user363243 on Stack Overflow See other posts from Stack Overflow or by user363243
Published on 2010-06-10T18:37:26Z Indexed on 2010/06/10 18:52 UTC
Read the original article Hit count: 93

Filed under:

I have a 'users' table which stores all of my websites users, some of which are technicians. The users table has a 'first_name' and 'last_name' field as well as other fields.

The other table is called 'service_tickets' which has a foreign key from users called technician_id. This gives me a real problem because when I am looking at the service_tickets table, the related user is actually a technician. That's why the service_tickets table has a technician_id and not a user_id field.

I am trying to accomplish something like this:

t = service_ticket.find_by_id(7)
t.technician.first_name        # notice how I don't do t.user.first_name

Is this possible in rails? I can't seem to get it to work...

Thank you for your help!

© Stack Overflow or respective owner

Related posts about ruby-on-rails