Single table lookups

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 %>

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