On Wed, Mar 9, 2011 at 9:53 AM, grady <[email protected]> wrote:
> 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" 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.

Shouldn't the assoc. be Artifact hasOne Preview, Preview belongsTo Artifact?

Althought the first % is unnecessary it shouldn't be a problem.

-- 
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

Reply via email to