hi there, do you know if it is only 1.2 ?
tia thomas On Jun 6, 5:54 pm, "Tane Piper" <[EMAIL PROTECTED]> wrote: > Thanks to Gwoo and PHPNut, eventually solved it! > > It's the lovely 'with' key, which currently isn't in the manual. Here > is it working: > > <?php > class Track extends AppModel { > > var $name = 'Track'; > > var $hasAndBelongsToMany = array( > 'Playlist' => array('className' => 'Playlist', > 'with' => 'PlaylistsTrack', > 'order' => > 'PlaylistsTrack.position ASC'), > ); > > ?> > > <?php > class Playlist extends AppModel { > > var $name = 'Playlist'; > var $hasAndBelongsToMany = array( > 'Track' => array('className' => 'Track', > 'with' => 'PlaylistsTrack', > 'order' => > 'PlaylistsTrack.position ASC'), > );} > > ?> > > <?php > > class PlaylistsTrack extends AppModel > { > var $belongsTo = array('Playlist', 'Track'); > > } > > ?> > > On 6/6/07, Tane Piper <[EMAIL PROTECTED]> wrote: > > > > > I forgot to mention, I have worked out how to access some of the data, > > such as when I am adding a new playlist, how to access the tracks > > there: > > > function admin_add() { > > if(!empty($this->data)) { > > $this->cleanUpFields(); > > $this->Playlist->create(); > > if($this->Playlist->save($this->data)) { > > $this->Session->setFlash('The Playlist has > > been saved'); > > $this->redirect(array('action'=>'index'), > > null, true); > > } else { > > $this->Session->setFlash('The Playlist > > could not be saved. Please, > > try again.'); > > } > > } > > $tracks = > > $this->Playlist->PlaylistsTrack->Track->generateList(null,null,null, > > '{n}.Track.id', '{n}.Track.trackname'); > > $this->set(compact('tracks')); > > } > > > But I just cannot figure out using $this->Playlist->read() how to get > > this data. When I print_r my returned array, all I get is this: > > > Array > > ( > > [Playlist] => Array > > ( > > [id] => 6 > > [title] => New Test Playlist > > [comments] => > > ) > > > [PlaylistsTrack] => Array > > ( > > ) > > > ) > > > Tane > > > On 6/6/07, Tane Piper <[EMAIL PROTECTED]> wrote: > > > Hey folks, > > > > Asking about it on IRC, and looking on the group I think I have half > > > got my code working for what I need to to. A bit of background first: > > > > I have added a media player to my site, which is controlled from the > > > backend and outputs to XSPF for the player. > > > > First off, I have my Track controller. In this, the user can upload a > > > track (using a behaviour) and it creates and entry into the database. > > > I also have a Playlist controller, which so far I have used a hABTM > > > association to create playlists with selected tracks. So far so good, > > > it works well - but the problem was that when adding the tracks, they > > > would be in the order of the id within the Track table. > > > > So, I decided I needed a position field in my join table. Now, > > > looking on the group I can see this is not supported by standard > > > hABTM, so what I have done is below: > > > > I created the model for the PlaylistsTrack(s) table: > > > > <?php > > > class PlaylistsTrack extends AppModel > > > { > > > var $belongsTo = array('Playlist', 'Track'); > > > } > > > ?> > > > > I then changed the associations in my existing models to hasMany: > > > > <?php > > > class Playlist extends AppModel { > > > > var $name = 'Playlist'; > > > > //The Associations below have been created with all possible keys, > > > those that are not needed can be removed > > > > var $hasMany = array('PlaylistsTrack' => array('foreignKey' => > > > 'playlist_id')); > > > var $recursive = 2; > > > } > > > ?> > > > > <?php > > > class Track extends AppModel { > > > > var $name = 'Track'; > > > > var $hasMany = array('PlaylistsTrack'=> array('foreignKey' => > > > 'track_id')); > > > var $recursive = 2; > > > } > > > ?> > > > > The problem is now, I'm not sure how to access the tracks for specific > > > playlists. For example, here is my current XSPF output method: > > > > function xspf($id = null) { > > > if(!$id) { > > > $this->Session->setFlash('Invalid Playlist.'); > > > $this->redirect(array('action'=>'index'), null, > > > true); > > > } > > > $this->layout = 'xml'; > > > $this->Playlist->recursive = 2; > > > $this->set('playlist', $this->Playlist->read(null, $id)); > > > } > > > > This grabs the Playlist data, but it doesn't get any of the tracks. I > > > would appreciate any help on this. > > > > A second point in in my PlaylistsTrack model - I also want to be able > > > to read the order of a select field, and assign the position to each > > > 'join', so my table might look something like this: > > > > | playlist_id | track_id | position | > > > --------------------------------------------- > > > | 1 | 1 | 0 | > > > | 1 | 3 | 1 | > > > | 1 | 2 | 2 | > > > > Is there a simple way do do this, possibly in a beforeSave ? > > > > Thanks, > > > Tane > > -- > Tane Piperhttp://webrocket.wordpress.com > > This email is: [ ] blogable [ x ] ask first [ ] private --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" 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 -~----------~----~----~----~------~----~------~--~---