Error when retrieving associated data on. Linux only

拈花ヽ惹草 提交于 2019-12-20 06:38:58

问题


Prior this problem I had another issue related to the same subject. The problem has been sorted thanks ta @ndm.

Link the previous problem: Cakephp 3. Windows and Linux OS returning different result when querying the database

I have an article page and I am retrieving the associated data with articles. Article comments.

I have the following line of code

$this->Articles->find()->contain('ArticleComments');

This line of code on both local Windows 10 machine and production Debian server retrieves all articles including their comment. find a link to a screenshot of the returned result using Cakephp debugging function pr($object)

Screenshot of the returned result: http://s29.postimg.org/f76brygw6/cakephp.jpg

Now the only problem I have, which occurs only on the production Debian server is that despite the aforementioned line of code is returning articles and article comments I cannot use this object. For an instance if I try the following code:

$this->Articles->find()->contain('ArticleComments')->toArray();

Or

$this->set('articles', $this->Articles->find()->contain('ArticleComments'));

I get this error:

Cannot convert value to integer InvalidArgumentException

And the following error in tmp/error.log: http://s14.postimg.org/4e88qp6j4/cakephp_error.jpg

Again, this error occurs only on my Debian server and if I retrieve just articles by the following code it works fine.

$this->Articles->find()

What I have done to fix this issue:

  1. Triple checked (twice) table and classes names. 100% sure the issue is not file naming one.
  2. checked both machines PHP and Cakephp version. My Debian server runs PHP 5.6.15-1~dotdeb+zts+7.1 (cli) and My Windows 10 runs PHP 5.6.8 (cli). Cakephp versions are the same. Cakephp 3.1.4

回答1:


The problem is, probably, the way you are loading the associations. You are required to tell Cake in what plugin your table class lives. Instead of doing this:

$this->hasMany('ArticleComments')

You need this:

$this->hasMany('Comments.ArticleComments')



回答2:


Problem solved!

The issue was not coming from Linux nor CakePHP.

On my local machine which happens to be Windows OS I am running MySQL version 5.6.24 and on my live server, which runs Linux debian I have MySQL 5.5.46.

I had database columns "datetime" which is supported in 5.6 but was causing a problem in version 5.5.

I simply changed the column type to "timestamp" and the issue was resolved.

Both environments are running different OS's and an enormous amount of time was spent to ensure the issue is not Windows to Linux problem(i.e. filename case sensitivity). CakePHP misleading error messages has delay me to resolve the problem also.

I am glad after more than a month the problem is fixed :D



来源:https://stackoverflow.com/questions/33982607/error-when-retrieving-associated-data-on-linux-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!