Quick description of the domain/model...

Working on a newsletter for a record shop...

Models: Newsletter, Releases, Formats

- Newsletter hasMany Releases
- Released belongsTo Formats

So basically a newsletter will display the new releases for the week
and each release has a format such as: CD, Tape, Vinyl etc...

Now I would like to split, the newsletter to only display all new
releases on Vinyl format on the front page and the others on separate
pages.

How would I do this? Bind, unbind?

If you look in the chapter about associations
(http://manual.cakephp.org/chapter/models), you can see that an
association can have a name that is different from the classname --
that allows you to have different associations for the same table. For
each of the association you can then use the 'conditions' field to set
conditions particular to this association.

So for instance you have two associations in your NewsLetter model, one
for the vinyls and one for the other types :

var $hasMany = array(
 'VinylReleases' => array(
   'className' => 'Release',
   'conditions'  => 'Release.type = "vinyl"'
 ),
 'NonVinylReleases' => array(
   'className' => 'Release',
   'conditions' => 'Release.type <> "vinyl"'
 )
);

Now when you call

$this->NewsLetter->find(...);

This should return an array containing a field 'VinylReleases' and
another field 'NonVinylReleases' with the correct data in it.

You can add other terms to that condition -- it's SQL -- so you could
add an extra condition to get only the releases of a certain time
period. If this needs to be done on the fly, then, yes, use
bind/unbind.

Anselm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to