So I have this method within the model. The same array is returned from above but I get a mysql error for the contain.
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'contain' at line 1 [CORE\cake\libs\model \datasources\dbo_source.php, line 521] function test() { $this->actsAs = array('Container'); $this->bindModel(array( 'hasMany' => array( 'TeamMember' => array( 'className' => 'TeamMember', 'foreignKey' => 'team_id', 'conditions' => array('TeamMember.status' => 'approved'), 'order' => 'TeamMember.joinDate ASC', 'dependent' => true, //'finderQuery' => 'SELECT User.username, User.handle, User.avatar FROM user AS User, teamMember as TeamMember WHERE User.id = TeamMember.user_id LIMIT 1' ), 'TeamGame' => array( 'className' => 'TeamGame', 'foreignKey' => 'team_id' ) ) )); $this->contain(array('TeamMember' => array('User'), 'TeamGame')); return $this->find('first'); } On Dec 6, 3:35 am, Adam Royle <[EMAIL PROTECTED]> wrote: > Add: > > var $actsAs = array('Containable'); > > to your Team model. > > Then add this before your find() call: > > $this->Team->contain('TeamMember' => array('User'), 'TeamGame'); > > Cheers, > Adam > > On Dec 6, 12:51 pm, gearvOsh <[EMAIL PROTECTED]> wrote: > > > 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---