Hi,
i want to show all current players of a club, but i have problems to
show them with the paginator. By the way i am not so sure about my way
of coding here:
First of all i have 2 HABTM assoziations in my club model:
var $hasAndBelongsToMany = array(
'CurrentPlayers' => array(
'className' => 'Player',
'joinTable' => 'clubs_players',
'foreignKey' => 'club_id',
'associationForeignKey' => 'player_id',
'unique' => true,
'conditions' => 'start_datetime <= CURRENT_TIMESTAMP AND
end_datetime > CURRENT_TIMESTAMP',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'AllPlayers' => array(
'className' => 'Player',
'joinTable' => 'clubs_players',
'foreignKey' => 'club_id',
'associationForeignKey' => 'player_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
);
1.) I am not so sure about if it really makes sense to work with two
assoziation here and not only with 'AllPlayers' and use then in the
find()-method a filter for the start- and end-datetimes... What do you
think?
My controller method for players looks like:
function index($club_id = null, $country_id = null, $state_id = null,
$city_id = null) {
$paginate = array();
if($club_id>0){
$this->Club = ClassRegistry::init('Club');
$this->Club->recursive = 1;
$club = $this->Club->find('first', array('conditions' =>
array('Club.id' => $club_id)));
$paginate = $club['CurrentPlayers'];
echo pr($paginate);
}
elseif($city_id>0){
$paginate = array('Player.city_id' => $city_id);
}
elseif($state_id>0){
$paginate = array('Player.state_id' => $state_id);
}
elseif($country_id>0){
$paginate = array('Player.country_id' => $country_id);
}
$players = $this->paginate('Player', $paginate);
$this->set('players', $players);
}
2.) Do i really have to work with ClassRegistry::init() or how do i
access to the club?
I am getting following error with paginate:
"SQL Error: 1052: Column 'id' in where clause is ambiguous"
Unfortunately i cannot work with something like
elseif($club_id>0){
$paginate = array('Club.id' => $club_id);
}
cause Club or ClubPlayers is unknown in the query or how i make it
known for Player properly?
Thanks for any help :)
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