I'm not sure that I follow all that but here's what I use:
function parentNode()
{
if (!$this->id) return null;
$data = $this->read();
return $data['User']['group_id']
? array (
'model' => 'Group',
'foreign_key' => $data['User']['group_id']
)
: null;
}
That looks like it would work for you but there area variety of ways
of doing this. It really depends on the model. In the same app I have
a Section model that has:
public function parentNode()
{
if (!$this->id) return null;
$parent_id = $this->field(
'parent_id',
array('Section.id' => $this->id)
);
return $parent_id
? array(
'model' => 'Section',
'foreign_key' => $parent_id
)
: null;
}
On Mar 22, 10:00 am, NdJ <[email protected]> wrote:
> Hi,
>
> I'm fairly comfortable with the CakePHP ACL mechanism even though she
> can be a little tough to manage at first. I have however come by some
> curious behavior using CakePHP 1.3 and the suggested Acts As a
> Requester code here:-http://book.cakephp.org/view/1547/Acts-As-a-Requester
>
> My problem is this:-
> When a new user record is created $this->data correctly contains a
> value for [User][group_id] - however if you are just updating a field
> within a user record $this->data will not contain any value for [User]
> [group_id] and thus code suggested in the book will return a null.
> This hence sets the corresponding users ARO record to have a NULL
> parent_id -- ouch.
>
> At this stage I don't know if the problem is my code or if it is a
> genuine problem with the suggested code in the docs. The example code
> has been this way for quite some time so I'm finding it hard be
> believe I'm the first to notice and report this.
>
> I've resolved by adjusting the code in parentNode() in the manner
> below.
>
> Anyway, before I go ahead and attempt to adjust the online docs for a
> topic that is already a challange to understand can anyone else
> confirm/deny the problem I'm seeing here? Do note that my "Group"
> model is named "UserGroup" and not just Group.
>
> Cheers,
> N
>
> /**
> * parentNode
> *
> * @return mixed
> */
> function parentNode() {
>
> if (!$this->id && empty($this->data)) {
> return null;
> }
>
> if (empty($this->data) or !isset($this->data['User']
> ['user_group_id'])) {
> $data = $this->read('user_group_id');
> }
> else {
> $data = $this->data;
> }
>
> return array('UserGroup' => array('id' => $data['User']
> ['user_group_id']));
> }
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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
To unsubscribe from this group, send email to
cake-php+unsubscribegooglegroups.com or reply to this email with the words
"REMOVE ME" as the subject.