Tuesday, September 24, 2013

Re: Cake PhP Beginner: nested associations and views

Thank you so much! It works perfectly as I want.

Il giorno lunedì 16 settembre 2013 16:50:46 UTC+2, Jeremy Burns ha scritto:
Have a look at the Containable behaviour, add it to your AppModel (so it is always available) and set recursive to -1 in your AppModel. Containable is your friend. It gives you complete control over what associated data is returned.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 16 Sep 2013, at 14:33:43, Luca Simonella <therm...@gmail.com> wrote:

Hi, this is my first week on CakePhP and I found it awesome.
I'm developing a web site for my fantasy football championship and I made a few model with the following associations:

Team has Many Player
Player belongTo Team
Player hasMany Vote
Vote belongTo Player

So relationships are Team --> Player --> Vote. Now I want to make a view that lists all the players for a specific team AND for each player I want to show statics about their votes. My Player mdoel is made like this:

class Player extends AppModel{
public $belongsTo = 'Team';
public $hasMany = array(
'Vote' => array(
'className' => 'Vote',
'fields' => array(
'AVG(Voto) as Media',
'SUM(Goal) as Goal',
'SUM(GoalSubito) as GoalSubito',
.... other fields with italian names btw
),
'group' => array('Giornata')
)
);
}

when I wrote view for a specific player it works, but If I'm going to wrote the specific team view, data about single player votes does not appear from debug.

Array  (      [Team] => Array          (              [ID] => 1              [Nome] => Lokomotiv Wagon              [Allenatore] => Luca "Ponch" Simonella              [Budget] => 320              [Stadio] => Julian Ross Stadium Memorial              [Maglia] =>               [Logo] =>               [id] => 1          )        [Player] => Array          (              [0] => Array                  (                      [ID] => 292                      [Nome] => AMELIA                      [Ruolo] => P                      [Squadra] => MILAN                      [Quota] => 1                      [QuotaIniziale] => 2                      [team_id] => 1                  )                [1] => Array                  (                      [ID] => 291                      [Nome] => ABBIATI                      [Ruolo] => P                      [Squadra] => MILAN                      [Quota] => 13                      [QuotaIniziale] => 13                      [team_id] => 1                  )
...
}

Have I to use recursive option? How can i go deeply on my association to retrieve data? I hope you could help.

Thank you

Luca

--
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+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@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/groups/opt_out.

No comments: