动态地将列添加到 DBIx::Class ResultSet
我有一个代表 eBay 拍卖的 DBIx::Class
对象。基础表有一个描述列,其中包含大量数据。描述列几乎从未使用过,因此它不包含在该表的 DBIx::Class
列列表中。这样,大多数查询就不会获取拍卖描述数据。
不过,我确实有一个脚本需要本专栏。在这种情况下,我想像访问任何其他列一样访问描述列的内容:
$auction->description
如何在不强制所有其他查询获取描述列的情况下完成此操作?
I have a DBIx::Class
object representing an eBay auction. The underlying table has a description column which contains a lot of data. The description column is almost never used, so it's not included in the DBIx::Class
column list for that table. That way, most queries don't fetch the auction description data.
I do, however, have one script that needs this column. In this one case, I want to access the contents of the description column as I would any other column:
$auction->description
How can I accomplish this without forcing all other queries to fetch the description column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在旧版本的
DBIx::Class
中(不确定版本号),以下内容曾经有效:这似乎不适用于现代版本的
DBIx:: 下的行更新:类。尝试在
DBIx::Class
0.08123 下进行更新会出现以下错误:“DBIx::Class::Relationship::CascadeActions::update(): No such column description at ...”
假设需要额外列的脚本正在其自己的进程中运行。你可以这样做:
当然,这是一个全球性的变化。添加该列后,同一进程中的其他代码将开始在查询中获取
description
列。更不用说,它有点丑陋。In older versions of
DBIx::Class
(not sure of the version number), the following used to work:That doesn't seem to work for row updates under modern versions of
DBIx::Class
. Trying that with an updateunder
DBIx::Class
0.08123 gives the following error: "DBIx::Class::Relationship::CascadeActions::update(): No such column description at ..."Assuming that the script needing the extra column is running in its own process. You can do something like this:
Of course, that's a global change. After adding the column, other code in the same process will start fetching the
description
column in queries. Not to mention, it's kind of ugly.