[Dbix-class] Differences in generated relationships

Dave Cross dave at dave.org.uk
Thu Feb 11 14:45:38 GMT 2021


I have a database that contains tasks and the dependencies between
those tasks. It contains two tables:

CREATE TABLE `task` (
  `id` int(11) NOT NULL,
  `done` tinyint(1) DEFAULT NULL,
  `title` char(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
)

CREATE TABLE `task_dependency` (
  `id` int(11) NOT NULL,
  `previous_task_id` int(11) NOT NULL,
  `next_task_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `previous_task_id` (`previous_task_id`),
  KEY `next_task_id` (`next_task_id`),
  CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`)
REFERENCES `task` (`id`),
  CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`)
REFERENCES `task` (`id`)
)

You'll see there are two foreign keys between task_dependency and
task. Other than the names, these columns are defined in exactly the
same way.

But when I use dbicdump to generate DBIC classes for these tables,
there's a subtle difference in the way the relationships are named. In
Task::Schema::Result::Task, I get the following relationships.

=head1 RELATIONS

=head2 task_dependencies_next_task

Type: has_many

Related object: L<Task::Schema::Result::TaskDependency>

=cut

__PACKAGE__->has_many(
  "task_dependencies_next_task",
  "Task::Schema::Result::TaskDependency",
  { "foreign.next_task_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 task_dependency_previous_tasks

Type: has_many

Related object: L<Task::Schema::Result::TaskDependency>

=cut

__PACKAGE__->has_many(
  "task_dependency_previous_tasks",
  "Task::Schema::Result::TaskDependency",
  { "foreign.previous_task_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

Note that the plurals are in different places in the relationship names.

task_dependencIES_next_task vs task_dependency_previous_taskS

If it matters, this is a MariaDB database. And here's the config file
I used with dbicdump:

schema_class Task::Schema

<connect_info>
  dsn   dbi:mysql:dbname=test;hostname=172.17.128.1
  user  test
  pass  test
</connect_info>

<loader_options>
  dump_directory        ./Testlib
  allow_extra_m2m_cols  1
</loader_options>

I'm using DBIx::Class::Schema::Loader version 0.07049.

This isn't a major problem, but I just know that I'll keep typing
these names incorrectly :-/

Is there anything I can do to fix this? Or is it expected behaviour?

Cheers,

Dave...



More information about the DBIx-Class mailing list