I'm pretty new to Perl and got this Catalyst project to maintain. There is a MySQL database, that is connected via DBIx and I need to do some changes. In the documentation of the project I found, how the model is created:
dev:~# script/prj_create.pl
model PrjDB DBIC::Schema
prj::Schema::PrjDB
create=static
preserve_case=1
moniker_map='sub {return $_[0];}'
col_accessor_map='sub {return $_[0];}'
inflect_plural='sub {return $_[0];}'
inflect_singular='sub {return $_[0];}'
exclude='^view_'
components=TimeStamp,PassphraseColumn,DynamicDefault
use_moose=1
dbi:mysql:prj root ********
In the database there are relationships like
company_user belongs_to company (foreign key)
company_user has_many company_user ("last_changed_by_user")
company_user has_many company (secondary relationship via "last_changed_by_user")
The original model that I got has following lines created in "company_user.pm":
__PACKAGE__->has_many(
"company",
"prj::Schema::PrjDB::Result::company",
{ "foreign.last_changed_by" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"company",
"prj::Schema::PrjDB::Result::company",
{ id => "company" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);
If I now try to recreate the model I get:
__PACKAGE__->has_many(
"company",
"prj::Schema::PrjDB::Result::company",
{ "foreign.last_changed_by" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
"company_2",
"prj::Schema::PrjDB::Result::company",
{ id => "company" },
{ is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
);
(Notice the "_2" suffix in the belongs_to package.)
With this model, all the existing code breaks as it can't find some methods anymore. I frankly don't really know, what to search for, so I hoped someone here can help me.
Is there any option in loader, that I need to set / unset or is it maybe something that doesn't even has to do anything with the loader?
Edit: The only thing I found for a {rel}_2 notation so far is in the ResultSet class where it says:
If the same join is supplied twice, it will be aliased to {rel}_2 (and similarly for a third time).
I don't know, if this is the source of my problem and how to circumvent it.
One thing, that i didn't had in my original question: the working model was created with a DBIx version of 2012(? I think, not documented) and I now use the newest available one.
I fixed the naming problem by remapping the wrong names in the generator script call via rel_name_map
. There are just two problematic joins, so the effort is sufficient for me. I know that this is no general solution, but maybe it helps someone.
I used rel_name_map
like so:
dev:~# script/prj_create.pl
model PrjDB DBIC::Schema
prj::Schema::PrjDB
create=static
preserve_case=1
moniker_map='sub {return $_[0];}'
rel_name_map="{company_2 => \"company\", user_2 => \"user\"}"
col_accessor_map='sub {return $_[0];}'
inflect_plural='sub {return $_[0];}'
inflect_singular='sub {return $_[0];}'
exclude='^view_'
components=TimeStamp,PassphraseColumn,DynamicDefault
use_moose=1
dbi:mysql:prj root ********