Ah, apologies for my lack of research...
The key point that I was missing (and I had read over the "Multiple
relations to the same
model"<http://book.cakephp.org/view/1046/Multiple-relations-to-the-same-model>
section)
was that in order to have multiple relations you *must* use a different
alias. I had both relationships pointing to "Artifact", which was breaking
the form in my add view. Once I switched the name of the alias to "Preview"
(in the artifact model $belongsTo variable) and "ArtifactPreview" (in the
asset model $hasMany variable) everything fell in to place.
One additional question that came from this ... what is the best practice
for limiting the type of the preview asset to an image file? (Since they
could be video, sound, etc.) In my Asset table I have a field for "type"
that stores the mime type. It seems to me that the best place for this
restriction would be in the model definition, limiting the preview asset
with something like:
class Artifact extends AppModel {
var $name = "Artifact";
// Model relationships
var $belongsTo = array(
"Preview" => array(
"className" => "Asset",
"foreignKey" => "preview_id",
"conditions" => array("Preview.type LIKE" => "%image%")
)
);
}
This doesn't appear to be doing anything, as pulling in the preview assets
in my controller ($previews = $this->Artifact->Preview->find('list')) is
still populating my Form helper ($this->Form->input("preview_id")) with all
of the assets.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php