Hi, I’m a bit rusty with this, but I’m trying to get some relationship
stuff working with an existing application and legacy database that I
have been working with. Here’s the way it works:
I have time_accounting which can belong to tickets and tickets belong
to queues. Ultimately, I am trying to get a list of all the
time_accounting tickets that exist under a queue. I have the following
models:
class TicketQueue < ActiveRecord::Base
def self.table_name() “queue” end
has_many :ticket, :foreign_key => ‘$queue_id’
end
class Ticket < ActiveRecord::Base
def self.table_name() “ticket” end
has_many :time_accounting, :foreign_key => ‘$ticket_id’
belongs_to :ticket_queue, :foreign_key => ‘$queue_id’
end
class TimeAccounting < ActiveRecord::Base
def self.table_name() “time_accounting” end
belongs_to :ticket, :foreign_key=> “ticket_id”
belongs_to :article, :foreign_key=> “article_id”
end
The belongs_to relationship between time accounting and tickets seems
to work, but I can’t get the one for queues and their tickets to work,
which I need to derive the time accounting data for the tickets in each
queue.
If I do something like this, it just hangs:
my_queue = TicketQueue.find 15
=> #<TicketQueue:0x2acc0f2db330 @attributes={“lock_notify”=>“0”,
“system_address_id”=>“1”,
“name”=>“interlink::interlink-internal-support”, “valid_id”=>“1”,
“state_notify”=>“0”, “follow_up_lock”=>“0”, “escalation_time”=>“0”,
“comments”=>"", “salutation_id”=>“1”, “create_by”=>“2”,
“create_time”=>“2006-08-28 14:13:53”, “move_notify”=>“0”,
“group_id”=>“5”, “id”=>“15”, “change_by”=>“2”,
“change_time”=>“2006-08-28 14:13:53”, “signature_id”=>“1”,
“unlock_timeout”=>“0”, “default_sign_key”=>"", “owner_notify”=>“0”,
“follow_up_id”=>“1”}>
my_queue.ticket
Does anyone see anything obvious that I am screwing up here? I can do
something like:
test = TimeAccounting.find 16
=> #<TimeAccounting:0x2acc0e7f1c98 @attributes={“time_unit”=>“0.25”,
“create_by”=>“2”, “create_time”=>“2006-09-01 08:29:07”, “id”=>“16”,
“change_by”=>“2”, “change_time”=>“2006-09-01 08:29:07”,
“ticket_id”=>“21”, “article_id”=>“73”}>
test.ticket.queue_id
=> 1
So the time_accounting relationship with tickets works. Although I am
not sure it works in reverse, as I get a similar hang if I pull up a
specific ticket, and then try to get the time_accounting information
from it.
Thanks,
Leah