Have recreated a test environment with your tables and models in
accordance with your specified model associations. Added some very few
test data and executed some of your find statements, to see if I could
make it produce the same (erroneous) SQL statements.
Testing using the code below:
[code]
$this->Song->recursive = -1;
for($i = 0; $i < 3500; $i++){
$this->Song->find(
'first', array(
'conditions' => array(
'Song.artist_id' => rand(1,2),
'Song.name' => 'Song number '.rand(1,7)
),
'fields' => array('Song.id', 'Song.name')
)
);
}
[/code]
After having executed more than 20000 find statements, I still could
not see any erroneous SQL statement. All created statements looks like
this:
[code]
SELECT `Song`.`id`, `Song`.`name` FROM `songs` AS `Song` WHERE
`Song`.`artist_id` = 2 AND `Song`.`name` = 'Song number 5' LIMIT 1
[/code]
Testing using the code below (from Song controller):
[code]
$this->Song->AlbumSong->recursive = -1;
for($i = 0; $i < 3500; $i++){
$this->Song->AlbumSong->find(
'count', array(
'conditions' => array(
'AlbumSong.album_id' => rand(1,3),
'AlbumSong.song_id' => rand(1,7)
)
)
);
}
[/code]
After having executed more than 20000 find statements, I still could
not see any erroneous SQL statement. All created statements looks like
this:
[code]
SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE
`AlbumSong`.`album_id` = 3 AND `AlbumSong`.`song_id` = 4
[/code]
My environment:
Apache/2.2.14
PHP 5.3.1
MySQL 5.0.5
CakePHP 1.3.2
Enjoy,
John
On 21 Nov., 19:51, "[email protected]" <[email protected]> wrote:
> Here are model setup:
>
> models/album.php
>
> <?php
> class Album extends AppModel {
> var $name = 'Album';
> var $belongsTo = array(
> 'Artist' => array(
> 'className' => 'Artist',
> 'foreignKey' => 'artist_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );
>
> var $hasAndBelongsToMany = array(
> 'Song' => array(
> 'className' => 'Song',
> 'joinTable' => 'albums_songs',
> 'foreignKey' => 'album_id',
> 'associationForeignKey' => 'song_id',
> 'unique' => true,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'finderQuery' => '',
> 'deleteQuery' => '',
> 'insertQuery' => ''
> )
> );
>
> var $hasMany = array(
> 'AlbumSong' => array(
> 'className' => 'AlbumSong',
> 'foreignKey' => 'album_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> )
> );}
>
> ?>
>
> models/album_song.php
>
> <?php
> class AlbumSong extends AppModel {
> var $name = 'AlbumSong';
> var $useTable = 'albums_songs';
> var $belongsTo = array(
> 'Song' => array(
> 'className' => 'Song',
> 'foreignKey' => 'song_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> ),
> 'Album' => array(
> 'className' => 'Album',
> 'foreignKey' => 'album_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );}
>
> ?>
>
> models/artist.php
> <?php
> class Artist extends AppModel {
> var $name = 'Artist';
> var $hasMany = array(
> 'Album' => array(
> 'className' => 'Album',
> 'foreignKey' => 'artist_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> ),
> 'Song' => array(
> 'className' => 'Song',
> 'foreignKey' => 'artist_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> ),
> 'ArtistGenre' => array(
> 'className' => 'ArtistGenre',
> 'foreignKey' => 'artist_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> )
> );}
>
> ?>
>
> models/artist_genre.php
>
> <?php
> class ArtistGenre extends AppModel {
> var $name = 'ArtistGenre';
> var $useTable = 'artists_genres';
> var $belongsTo = array(
> 'Artist' => array(
> 'className' => 'Artist',
> 'foreignKey' => 'artist_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> ),
> 'Genre' => array(
> 'className' => 'Genre',
> 'foreignKey' => 'genre_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );}
>
> ?>
>
> models/genre.php
>
> <?php
> class Genre extends AppModel {
> var $name = 'Genre';
> var $hasAndBelongsToMany = array(
> 'Artist' => array(
> 'className' => 'Artist',
> 'joinTable' => 'artists_genres',
> 'foreignKey' => 'genre_id',
> 'associationForeignKey' => 'artist_id',
> 'unique' => true,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'finderQuery' => '',
> 'deleteQuery' => '',
> 'insertQuery' => ''
> )
> );
>
> var $hasMany = array(
> 'ArtistGenre' => array(
> 'className' => 'ArtistGenre',
> 'foreignKey' => 'genre_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> )
> );}
>
> ?>
>
> models/song.php
>
> <?php
> class Song extends AppModel {
> var $name = 'Song';
> var $belongsTo = array(
> 'Artist' => array(
> 'className' => 'Artist',
> 'foreignKey' => 'artist_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );
> /*
> var $hasAndBelongsToMany = array(
> 'Album' => array(
> 'className' => 'Album',
> 'joinTable' => 'albums_songs',
> 'foreignKey' => 'song_id',
> 'associationForeignKey' => 'album_id',
> 'unique' => true,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'finderQuery' => '',
> 'deleteQuery' => '',
> 'insertQuery' => ''
> )
> );
> */
> var $hasMany = array(
> 'AlbumSong' => array(
> 'className' => 'AlbumSong',
> 'foreignKey' => 'song_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> )
> );}
>
> ?>
>
> That is pretty much of it. For sake of brevity I removed validation
> code.
>
> Thanks a lot!
[snip]
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