如何调试dbix ::班级?
最近,我从事一个Perl项目,要求我使用DBIX ::类作为ORM与数据库进行交互。我发现最烦人和耗时的一件事就是试图调试并了解正在发生的事情。
我对此感到特别沮丧,错误我正在获得列“ xxxxxx”,其中子句模棱两可
,我发现了是什么原因导致了此错误。这是因为我在xxxxxx属性上连接的两个不同表中要求列,而在列表中,该列没有被别名。这导致dbix ::类不知道要使用哪个列。
最令人沮丧的是不知道dbix ::班级在做什么,这使我对错误来自何处有很多疑问。
如何有效调试这种dbix :: class
错误?
I was recently working on a Perl project that required me to use DBIx::Class as the ORM to interact with a database. One of the things I found most annoying and just time consuming was just trying to debug and understand what was happening.
I was especially frustrated with and error I was getting Column 'XXXXXX' in where clause is ambiguous
and I figured out what was causing this error. It was down to the fact I was requesting columns from 2 different tables which where joined on the XXXXXX attribute and in the WHERE clause the column wasn't being aliased. This lead to DBIx::Class not knowing which column to use.
The most frustrating thing was not knowing what DBIx::Class was doing, leading me to have many doubts about where the error was coming from.
How to efficiently debug this kind of DBIx::Class
errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我知道错误是什么,但是我不知道造成的位置。如果这是旧的SQL,我会自己简单地添加别名,但是我不知道该如何在dbix :: class中做到这一点。而且,我不知道实际执行了什么SQL查询,这使情况变得更糟。
那是我发现
as_query
方法的时候://metacpan.org/pod/dbix :: class :: resultset#as_query ),登录后,会打印出dbix :: class class excute的SQL查询。 生活改变者。使我摆脱了很多麻烦,并给了我所需的东西。我能够解决这个问题后不久。故事的寓意:如果您在看到DBIX ::班级正在做什么困难,请使用此操作并使自己免于无数头痛。
So I knew what the error was, but I didn't know exactly where it was being caused. If this was plain old SQL I would've simply added the aliases myself but I didn't know how to do that in DBIx::Class. Moreover, I had no clue what SQL query was actually being executed, which made things even worse.
That's when I found out about the
as_query
method (https://metacpan.org/pod/DBIx::Class::ResultSet#as_query) which, when logged, prints out the SQL query that DBIx::Class executes. LIFE CHANGER. Saved me from so much trouble and gave me exactly what I needed. Shortly after I was able to solve the issue.Moral of the story: if you're having trouble seeing what DBIx::Class is doing, use this and save yourself from countless headaches.
您可以通过设置
dbic_trace
环境变量1
或文件名来启用调试。这是在 dbix :: class ::手动::故障排除
You enable debugging by setting the
DBIC_TRACE
environment variable to1
or a filename.That's documented at the very top of DBIx::Class::Manual::Troubleshooting