You are welcome MarkB

And thank you for reporting back :)
John

On Monday, 12 October 2015 17:49:43 UTC+3, MarkB wrote:
>
> And that is exactly the information I needed - I WAS going about it the 
> wrong way, and that 'multiple relations' link you provided set me straight. 
> Definitely a case of RTFM, though I think I had looked at that very early 
> on in the learning process and not got my head round it. Whereas now it 
> seems really rather simple and straightforward.
>
> Thank you John!
>
>
> On Tuesday, 6 October 2015 19:02:25 UTC+1, John Andersen wrote:
>>
>> You have not provided any information on how the Request and User are 
>> related in your models.
>>
>> Request belongsTo Provider(User)
>> Request belongsTo School(User)
>>
>> Provider(User) hasMany Request
>> School(User) hasMany Request
>>
>> Those two relationships can be defined in the models. Have you done so?
>> See Multiple relations to the same model:
>>
>> http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#multiple-relations-to-the-same-model
>>
>> When everything has been defined correctly, you should be able to 
>> retireve not only the Request, but also the related Provider(User) and 
>> School(User).
>>
>> Check also the use of Containable in your models. It will make your life 
>> easier in my opinion.
>> http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html
>>
>> Enjoy, John
>>
>> On Tuesday, 6 October 2015 17:13:59 UTC+3, MarkB wrote:
>>>
>>> Hi,
>>>
>>> Over the past year I have built a very unwieldy complex event management 
>>> system for an education science festival as my first CakePHP project but I 
>>> am having trouble getting my head around what is probably a very basic 
>>> CakePHP problem. I may even be going about this completely the wrong way.
>>>
>>> To simplify, I have 3 models - *Event, Request *and *User*. 
>>>
>>> *Users* have 3 roles - *Admin*, *Schools* and *Provider*.
>>>
>>> *Providers* offer events and *Schools *can request them, with details 
>>> stored in the related tables. *Admins w*ould then check them over and 
>>> click 'Accept' to then forward the *Schools* info to the *Providers *
>>> etc.
>>>
>>> Now, as both *Providers* and *Schools* are *Users*, and as I can only 
>>> have one user_id field in my *Requests* table, I called the *Providers* 
>>> field providers_id
>>>
>>> The problem is that when I'm trying to output a list of *Request *data to 
>>> my view (on screen and via CSV file) with the *Providers* details and 
>>> *Schools* details, it can't pull anything for the *Providers *but their 
>>> ID.
>>>
>>> How do I get their details into the data I'm sending to my view?
>>>
>>> I've tried the following Hash function but it puts the required details 
>>> of the provider from the last row into ALL the rows. I tried it without the 
>>> {n} expression and it just throws an error.
>>>
>>> Many thanks,
>>> MarkB.
>>>
>>> $requests = $this->Request->find('all');
>>>   
>>> foreach ($requests as $row):
>>>   
>>> $provider = 
>>> $this->Request->User->findById($row['Request']['provider_id']);
>>>
>>> $providerName = $provider['User']['firstname'] . ' ' . 
>>> $provider['User']['surname']; 
>>>
>>> $data = Hash::insert($requests, '{n}.Request.provider', $providerName);
>>>
>>> endforeach;
>>>
>>> $this->set('requests', $requests);
>>>
>>>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to