Friday, June 4, 2010

Query Results, Empty Array

I've searched the group a bit and haven't found anything that seems to
exactly solve my problem. Let me begin with the basics:

This is a website which I am transitioning from an old ASP site into
CakePHP. The site is driven by an MS-SQL database and being served
from a Macintosh XServer running Apache2. So I am building Models
based on the current database table structure and working from there.
All of the connections seem to be working fine - queries are working
perfectly - with the exception of my current problem.

The problem is that in some cases, queries seem to work fine but the
resulting array ends up being empty. There's nothing fancy about the
query function itself:

public function getPage($id) {
$page = $this->find('first', array('conditions' => array('pageid' =>
$id, 'Page.default_levelid = Page.levelid'),
'recursive' => 3
));
return $page;
}

And the resulting ['Page'] array is fine. The problem is the next
associated Model, the PageChart model. Here is where I associate it to
Page:

var $hasMany = array('PageChart' => array('foreignKey' => 'pageid',
'order' => 'line ASC'));

In the CakePHP query table from the debug mode shows a proper query
returning 6 PageChart results. However, in the returned array, the
['PageChart'] sub-array is completely empty. There are currently no
associated Models for the PageChart model - I've removed them in order
to limit the scope of the problem.

I stress again that this is only a problem with certain queries for
certain pages, not others. I am sure that, under the circumstances,
there must be something about the data that is causing an issue.
Otherwise, I would expect that the result would be either consistently
right or consistently wrong, but not a bit of Column A and a bit of
Column B.

What I'm hoping someone can shed some light on is why CakePHP might
bork on data but not give an error message. Character encoding
problems? Spaces? Something like that?

I really appreciate the help.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: