in reply to SQL question: Insertion with FK constraint

I would just create a subroutine to translate a property to a property id. Here's one that also implements a cache:
my %property_id; sub property_id { my ($db, $property) = @_; my $pid; unless (defined($pid = $property_id{$property}) { ($pid) = $db->query(..., $property)->list; unless (defined($pid)) { $db->query("INSERT ...", $property); $pid = $db->last_insert_id(); } $property_id{$property} = $pid; } return $pid; }

When inserting a record that has a property FK, just call the subroutine for its value, and it will get created if necessary.