为什么当我的关系看起来正确时,我得到一个未定义的属性错误? [英] Why am I getting an undefined property error when my relationships seem correct?

查看:115
本文介绍了为什么当我的关系看起来正确时,我得到一个未定义的属性错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,我不能弄清楚,但应该很简单。

我的cakePHP(1.3)应用程序中有以下模型结构:

I'm having a slight problem that I can't figure out, but should be really simple.
I have the following model structure in my cakePHP (1.3) app:

ProspectiveQuote [hasMany] QuoteUnit [belongsTo] Unit

ProspectiveQuotesController行:

but in my ProspectiveQuotesController the line:

$ this-> ProspectiveQuote-> QuoteUnit-> Unit-> find('list'); / code>

$this->ProspectiveQuote->QuoteUnit->Unit->find('list');

给我以下错误:

未定义属性:AppModel :: $ Unit

当然,它不应该查看AppModel,看看QuoteUnit。

如果我做 $ this-> ProspectiveQuote-> QuoteUnit-> find('all')结果(allbeit没有任何相关的模型数据...),所以它明显找到了足够好的QuoteUnit,我已经仔细检查了它与Unit的关系,这一切似乎很好...

Of course, it shouldn't be looking at AppModel, it should be looking at QuoteUnit.
If I do $this->ProspectiveQuote->QuoteUnit->find('all') it seems to get results (allbeit without any related model data...) so it obviously finds the QuoteUnit well enough, and I have double-checked its relationship with Unit, and it all seems fine...

看起来像一个简单的问题。从我可以看到的人有这个问题通常有他们的模型名称错误(或复数),但这不是这里的情况...

我可以做错了什么?

Seems like a simple enough problem. From what I can see people with this problem usually have their model names wrong (or plural) but this is not the case here...
What could I be doing wrong?

推荐答案

我想说的是仔细检查你的模型关联的语法,以确保它们是正确的。

I would say to double check over the syntax of your model associations to make sure they are correct. Or back them up, and bake out some new models to test with, just to ensure that it's how you expect it.

另一个伟大的事情是抓取DebugKit http://www.ohloh.net/p/cakephp-debugkit 这将帮助你看到你的变量和你的sql查询。

Another great thing is to grab the DebugKit http://www.ohloh.net/p/cakephp-debugkit Which will help you to see your variables and your sql queries.

正如Leo的评论中提到的,我会尝试避免 uses()放置,或者把1.2一点大的开销放到你的堆栈上。

As mentioned in Leo's comment I would try and avoid uses() as it puts, or did put in 1.2 a bit of a big overhead onto your stack.

这篇关于为什么当我的关系看起来正确时,我得到一个未定义的属性错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆