DBIx::Class - 此关系缓存在哪里?

发布于 2024-12-13 05:19:18 字数 671 浏览 0 评论 0原文

我有一个 Order 实体和一个 Address 实体,在我的 Schema::Result::Order 模块中,我有一个简单的所属关系:

__PACKAGE__->belongs_to( "address", 'Schema::Result::Address', 
                                             { addressid => 'addressid' });

我使用 DBIC_TRACE=1 运行此代码>:

my $order = $schema->resulset('Order')->find($id);
my $add1 = $order->address;
my $add2 = $order->address;

我只看到一个 SELECT ... FROM ADDRESS ... 查询,因此显然第二个 $order->address 方法没有访问数据库。

所以这可能是一个简单的问题,但是地址对象缓存在哪里? (在 $order 对象中?)

其次,此缓存是否可配置(即我可以将 DBIC 配置为缓存这些关系)吗?

I have an Order entity and an Address entity, and in my Schema::Result::Order module I have a simple belongs to relationship:

__PACKAGE__->belongs_to( "address", 'Schema::Result::Address', 
                                             { addressid => 'addressid' });

I run this code with DBIC_TRACE=1:

my $order = $schema->resulset('Order')->find($id);
my $add1 = $order->address;
my $add2 = $order->address;

and I only see one SELECT ... FROM ADDRESS ... query, so apparently the second $order->address method is not hitting the database.

So this might be a simple question, but where is the address object getting cached? (in the $order object?)

Secondly, is this caching configurable (i.e. can I configure DBIC to not cache these relationships)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦爱 2024-12-20 05:19:18

我认为您的订单与地址关系的方式您将只有一个订单地址:

__PACKAGE__->belongs_to( "address", 'Schema::Result::Address', 
                                            { addressid => 'addressid' });

如果您的订单将有许多您想要的地址:

__PACKAGE__->has_many( "address", 'Schema::Result::Address', 
                                            { addressid => 'addressid' });

那么您可以通过多种方式检索地址:

my $address_rs = $order->search_related('address',{});
while(my $row = $address_rs->next) {
#$row has an address record
}

我不确定如何缓存在这种情况下有效

my $order = $schema->resulset('Order')->find($id);
my $add1 = $order->address;
my $add2 = $order->address;

但是如果您像这样访问地址记录:

my $address_rs = $order->search_related('address',{});

您可以使用查询属性控制它:

https://metacpan.org/module/DBIx::Class::ResultSet#cache

I think the way you have your order to address relationship you will only have one address to the order:

__PACKAGE__->belongs_to( "address", 'Schema::Result::Address', 
                                            { addressid => 'addressid' });

If your order will have many addresses you will want:

__PACKAGE__->has_many( "address", 'Schema::Result::Address', 
                                            { addressid => 'addressid' });

Then you can retrieve the addresses a number of ways:

my $address_rs = $order->search_related('address',{});
while(my $row = $address_rs->next) {
#$row has an address record
}

I am not sure how the caching works in this situation

my $order = $schema->resulset('Order')->find($id);
my $add1 = $order->address;
my $add2 = $order->address;

But if you access your address record like this:

my $address_rs = $order->search_related('address',{});

you can control it with your query attributes:

https://metacpan.org/module/DBIx::Class::ResultSet#cache

失去的东西太少 2024-12-20 05:19:18

找到答案:它缓存在 $order->{_relationship_data}->{address} 中。

尚未确定是否可以禁用该缓存。

Found the answer: it's cached in $order->{_relationship_data}->{address}.

Haven't determined if that caching can be disabled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文