perl - index is not visible to DBIx::Class -
i have small perl code going add record table confused why dbic not able see primary key?
i not able find answer anywhere. first names of table , columns camelcase, changed underscore won't run :(
$ ./test.pl dbix::class::resultsource::unique_constraint_columns(): unknown unique constraint node_id on 'node' @ ./test.pl line 80 code:
sub addnode { $node = shift; $lcnode = lc($node); $id = $schema ->resultset('node') ->find_or_create ( { node_name => $lcnode }, { key => 'node_id' } ); return $id; } table details:
mysql> desc node; +------------+-----------------------+------+-----+---------+----------------+ | field | type | null | key | default | | +------------+-----------------------+------+-----+---------+----------------+ | node_id | mediumint(5) unsigned | no | pri | null | auto_increment | | node_name | varchar(50) | no | | null | | | node_notes | varchar(1000) | yes | | null | | +------------+-----------------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) dbix::class::resultset:
$ cat node.pm use utf8; package testdb::schema::result::node; # created dbix::class::schema::loader # not modify first part of file use strict; use warnings; use base 'dbix::class::core'; __package__->table("node"); __package__->add_columns( "node_id", { data_type => "mediumint", => { unsigned => 1 }, is_auto_increment => 1, is_nullable => 0, }, "node_name", { data_type => "varchar", is_nullable => 0, size => 50 }, "node_notes", { data_type => "varchar", is_nullable => 1, size => 1000 }, ); __package__->set_primary_key("node_id"); # created dbix::class::schema::loader v0.07045 @ 2017-08-21 22:14:58 # not modify or above! md5sum:bwxf98hpljgnbu93aarykq # can replace text custom code or comments, , preserved on regeneration 1;
https://metacpan.org/pod/dbix::class::resultset#find:
to aid preparing correct query storage may supply
keyattribute, name of unique constraint (the unique constraint corresponding primary columns namedprimary).
(emphasis mine.)
in other words, use primary key, need specify { key => 'primary' }. other key attribute looked name of additional unique constraint.
wiki
Comments
Post a Comment