Forum: Ruby on Rails Problem with large join table and ActiveRecord

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
95542f4645c6d32f235ac8c376aa0964?d=identicon&s=25 Robert Boone (rlb3)
on 2005-12-23 16:10
Hello,

   I'm having a hard time explaining this, so I hope i can say this
correctly. I have these tables:

   people
     id
     fname
     lname

   departments
     id
     name

    buildings
    id
    name
    room

    wtkeys
    id
    key_number
    key_way

   Issued_keys
     id
     people_id
     department_id
     building_id
     wtkey_id
     date_issued

    My question is when i need to insert a new issued_key do I just do
something like:

    person = Person.new
    person.fname = "Robert"
    person.lname = "Boone"
    person.save!

    dept = Department.new
    dept.name = "IT"
    dept.save!

    building = Building.new
    building.name = "CC"
    building.save!

    wtkey = Wtkey.new
    wtkey.key_number = "1234"
    wtkey.key_way       = "AAAA"
    wtkey.save!

    issued_key = IssuedKey.new
    issued_key.people_id         = person.id
    issued_key.department_id  = dept.id
    issued_key.building_id       = building.id
    issued_key.wtkey_id           = wtkey.id
    issued_key.date_issued      = Time.now
    issued_key.save!

    This seems very un-rails-like to me (but I could be wrong). Is there
there a better way to do this. And I won't object to changing the
database.

Thanks,
Robert Boone
This topic is locked and can not be replied to.