简体   繁体   English

DBIx::Class 错误“找不到 XXX 的来源”

[英]DBIx::Class error "Can't find source for XXX"

When I try to dump database with Fixtures :当我尝试使用Fixtures转储数据库时:

dbic-migration --schema_class App::Schema --database PostgreSQL -Ilib dump_all_sets

I got error:我有错误:

DBIx::Class::Schema::source(): Can't find source for Schet at /home/xxx/lib/perl5/x86_64-linux/Moose/Meta/Method/Delegation.pm line 110

In main application I have no problem to write:在主应用程序中,我没有问题可以写:

$schema->resultset('Schet')

How to fix this error and dump data into fixtures?如何修复此错误并将数据转储到设备中?

in the DBIx::Class::Schema::Loader we are connecting to the temporary schema.DBIx::Class::Schema::Loader 中,我们连接到临时模式。

When connection occur the schema is cloned当连接发生时,模式被克隆

But because of there only schema name is passed nothing is cloned and, as result, has empty class mapping.但是因为只传递了模式名称,所以没有克隆任何内容,因此具有空的类映射。 Which is wrong.这是错误的。

If you look carefully you will see that cloning occur twice: here and here .如果仔细观察,您会发现克隆发生了两次: herehere This extra cloning is wasteful and should be refactored.这种额外的克隆是浪费的,应该重构。

As work around here should be passed reblessed into required namespace cloned schema:因为这里的工作应该被传递到所需的命名空间克隆模式中:

sub _make_schema_at {
  my ($self, $name, %extra_opts) = @_;
  my $schema = $self->schema->clone;
  bless $schema, $name;
  DBIx::Class::Schema::Loader::make_schema_at
    $schema, {_merge_opts(%extra_opts)}, [{_rearrange_connect_info($schema->storage)}];
}

UPD UPD

Lately , when new loader is created, the naming is forced to current instead of passed argument, which, in its turn, is cloned from application schema. 最近,当创建新的加载器时, naming被强制为current而不是传递的参数,而后者又是从应用程序模式中克隆出来的。 (I do not check that, but when application will have its own naming , this will cause problems when dumping data) and loader is invoked again . (我不检查,但是当应用程序有自己的naming ,这会在转储数据时导致问题)并再次调用加载程序 Here loader loads classes based on table names instead of package names( how it is done at __PACKAGE__->load_namespaces( ... ) )这里加载器根据表名而不是包名加载类(它是如何在__PACKAGE__->load_namespaces( ... )

Finally @to_register lists differ:最后@to_register列表不同:

Here 这里

[
  Ip,
  App::Schema0::Result::Ip,
]
[
  Scheta,
  App::Schema0::Result::Scheta,
]

Here : 在这里

[
  IP,
  App::Schema::Result::IP,
],
[
  Schet,
  App::Schema::Result::Schet,
],

Ran into this recently, within a docker container.最近在一个 docker 容器中遇到了这个问题。 Curiously, some DBIx directories had the wrong permissions on them.奇怪的是,一些 DBIx 目录对它们有错误的权限。 They need to at least be readable.它们至少需要具有可读性。 Also check file/directory ownership.还要检查文件/目录所有权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM