Forum: Ruby on Rails Single table lookups

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.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-05-30 18:50
(Received via mailing list)
I'm struggling with a single table type (self) lookup.

my 'personnel' model has a supervisor_id and is_supervisor column.

The supervisor's select list is created by
  @supv = Personnel.find(:all,
   :conditions => ["is_supervisor = true"],
   :order => 'last_name')

in my personnel model, I have the following...

  def supervisor
    if Personnel.find_by_id(self.supervisor_id) == nil then
      Personnel.find_by_id(self.id).suwholename
    else
      Personnel.find_by_id(self.supervisor_id).suwholename
    end
  end

where 'suwholename' is an aggregate value of the first, middle, last
names.

The following view code produces a select list of supervisors...

  <%= options = [['Select', '']] + @supv.collect {
     |supv| [supv.suwholename, supv.id] }
     select 'personnel', 'supervisor_id', options %></TD>

but I have 2 problems...

1. If there is no supervisor_id, I get an error...
   PGError: ERROR:  invalid input syntax for integer: ""
   : SELECT * FROM personnels WHERE (personnels."id" = '' )  LIMIT 1

2. When I have a supervisor_id, it doesn't come up as 'selected' in the
select list.

I have struggled for a while with this and can't seem to make any
headway.

Craig
This topic is locked and can not be replied to.