Friday, December 5, 2008

Re: Custom queries/sql in models/behaviors

Ok thats weird, I dont have foreign keys really setup but it still
works. Im using $hasMany for members and games. But within the
TeamMember and TeamGame arrays, is there way to get more information
returned? I would need the members name, avatar, etc.

Array
(
[0] => Array
(
[Team] => Array
(
[id] => 1
[status] => approved
[name] => chair
[tag] => _h_
[urlName] =>
[website] =>
[irc] =>
[about] =>
[servers] =>
[logo] =>
[createDate] => 0
[state_id] => 0
[country_id] => 0
[created] =>
[modified] =>
)

[TeamMember] => Array
(
[0] => Array
(
[id] => 4
[team_id] => 1
[user_id] => 32
[role] => captain
[status] => approved
[joinDate] => 1211498560
)
)

[TeamGame] => Array
(
[0] => Array
(
[team_id] => 1
[gameSystem_id] => 3
)
)
)
)

On Dec 5, 4:08 pm, gearvOsh <mileswjohn...@gmail.com> wrote:
> Because I cant use foreign keys so all of those features are useless
> to me. I also cant use linked models.
>
> On Dec 5, 1:12 pm, teknoid <teknoid.cake...@gmail.com> wrote:
>
> > > I am not a big fan of the model system because its very limiting if you have advanced queries.
>
> > How did you come to that conclusion?
>
> > ...
>
> > If you properly created your models and associations, a simple find
> > ('all') will give you: Team, Roster, Game and League models with all
> > the relevant info.
>
> > On Dec 4, 6:23 pm, gearvOsh <mileswjohn...@gmail.com> wrote:
>
> > > Ok in my current system (its a gaming league) I have packages. I will
> > > use a Team package as an example. In this Team package I have a method
> > > getTeamInfo() which calls out to external queries. I do this so I only
> > > have to write a query once and can access its results through a method
> > > call. I prefer this way instead of having to write the same query over
> > > and over for different instances.
>
> > > require('teamExt.php');
> > > require('userExt.php');
>
> > > class Team {
>
> > >         public static function getTeamInfo($team_id) {
> > >                 $team = TeamExt::getTeamInfo($team_id);
>
> > >                 if (!empty($team)) {
> > >                         $team['roster'] = TeamExt::getRoster($team_id);
> > >                         $team['games']  = TeamExt::getGamesPlayed($team_id);
> > >                         $team['stats']  = TeamExt::getStats($team_id);
> > >                         $team['leader'] = UserExt::getUser($team['leader_id']);
> > >                 }
>
> > >                 return $team;
> > >         }
>
> > > }
>
> > > Now when I call Team::getTeamInfo I should have its team info, roster,
> > > games played, the team leader and league statistics. Now the problem
> > > with CakePHP is its model system. I am not a big fan of the model
> > > system because its very limiting if you have advanced queries. I was
> > > thinking of doing it this way:
>
> > > Class Team = Model Team
> > > TeamExt = Team Behavior
> > > UserExt = User Behavior
>
> > > $team = $this->Team->getTeamInfo();
>
> > > But how would I do custom queries in a behavior? And the logic for
> > > behavior is wrong with my idea anyways. Anyone have an idea of how I
> > > can accomplish my setup in CakePHP, because this is the one thing
> > > stopping me from using CakePHP. And no I will not use joins.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: