My favorites | Sign in
Logo
             
New issue | Search
for
| Advanced search | Search tips
Issue 153: Bug with calls like MyActiveRecord->withText()->withUser()->find(...) and null result
1 person starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----
Type-Defect
Priority-Medium
Milestone-3.1.7


Sign in to add a comment
 
Reported by anbie...@icolo.ch, May 10, 2009
What steps will reproduce the problem?
1. call MyActiveRecord->withText()->withUser()->find(...) (important: at 
least 2 times withXXX()) with a criteria such that the result is NULL (no 
record found)
2. then use another ActiveRecord like this: MyOtherActiveRecord-
>withSomething()->find(...) (important: at least one withXXX())

What is the expected output? What do you see instead?
It will complain about properties not found in MyOtherActiveRecord (unless 
MyOtherActiveRecord doesn't have the same properties as MyActiveRecord).

Version:
prado 3.1.5a

Fix proposition:
The problem lies in class TActiveRecordRelation, method __call: If the 
result of find() is null, the static variable $stack still references some 
stuff related to the ActiveRecord. If you then use another ActiveRecord 
these references are confusing it. Therefore I propose to clear the 
"stack" if the result is null. Like this:

modify method TActiveRecordRelation::__call() as follows:
[code]
if ($validArray || ...) {
	...
}
elseif($results instanceof TActiveRecordRelation) 
	$stack[] = $this; //call it later
elseif ($results === null) {
	$stack = array();
}
[/code]

Comment 1 by Christophe.Boulain, May 29, 2009
(No comment was entered for this change.)
Labels: -Milestone-3.1.5 Milestone-3.1.6
Comment 2 by Christophe.Boulain, Jul 22, 2009
Move to 3.1.7
Labels: Milestone-3.1.7
Comment 3 by labrut, Aug 17, 2009
This modifications maybe works :

else if ($results === null || !$validArray)
{
   $stack = array();
}
patch_issue153.patch
574 bytes   Download
Sign in to add a comment

Hosted by Google Code