| View previous topic :: View next topic |
| Author |
Message |
PaulKolin
Joined: 25 May 2006 Posts: 108
|
I have 2 models, say A hasMany B and B has a afterFind() in the model class. When doing a a->read() it ends up calling the
B->afterFind() when getting the data. The inconsistancy is that when b->read() is called the structure of $results passed into the function is
$results['name']['field']='value' but when b::afterFind() is called from a->read() the structure of $results is $results['name'][0]['field'] = 'value' .
Because of the hasMany the structure of the data makes sense, but I'm curious if you intended the afterFind() to have to cope with receiving differently
Formatted structures from associations. |
| |
|
|
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
B->afterFind is still called
A I mean
But b is last
Set recursive = 0 or -1 |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
Right, but the $results has an extra dimention and the handling logic needs to be different to handle it if coming from an association,
It seems undesireable to have to code that logic into the afterFind to me, and I wanted your point of view. am I clear in explaining what data I'm seeing?
When b->read() is called the structure of $results passed into the function is $results['name']['field']='value' but when b::afterFind() is called from a->read() the structure of $results is $results['name'][0]['field'] = 'value' .
So my foreach($results is breaking on the association because it has the extra dimention. |
| |
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
The structure is correct
They way it is returned |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
| I understand the structure, and it makes sense because of the hasMany. |
| |
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
| What are you trying to do in the afterFind? |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
| The problem is when $results is a 3? dimention array, from the association, and a 2 dimention array from the model itself. |
| |
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
You need to take that into account with your code PaulKolin
Like I said, set recursive to 0 or -1 so the hasMany are not returned |
| |
|
|
PaulKolin
Joined: 25 May 2006 Posts: 108
|
| Right, I was jsut typing, if it was your opinion of people should have to do so. |
| |
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
Yes
The core sends it to your methods in a set format
This is consistent across the board |
| |
|
|
| Page 1 of 2 |
Goto page 1, 2 Next |
|