Saturday, June 19, 2010

Re: DavidPersson Media plugin HABTM

Hi Biusso,

That looks like a little more complex setup you're heading for.
Remember that the Attachment model which comes with the plugin is just
a suggestion for one specific setup of media tables (a monolithic/
polymorphic one). Try to remove the Polymorphic behavior from the
model (you can than drop the "model" and "foreign_key" fields of the
attachments table, too). I've personally never used the behaviors with
a HABTM setup, so there might be some things which won't work.

If you are interested in adding your specific setup to the plugin
wiki, you'll find the page where I collect such stuff here:
http://wiki.github.com/davidpersson/media/recipes

- David


On 16 Jun., 17:29, Fabio <fabio.gualti...@gmail.com> wrote:
> Hello everyone, I just started using CakePHP. I followed the blog
> tutorial and would like to attach images to posts with David Persson
> media plugins, but I wonder if it's possible to use a "many to many"
> relation (habtm).
> I made this structure in the database:
>
> posts table:
>    id
>    title
>    body
>
> attachments table:
>    id
>    model
>    dirname
>    basename
>    checksum
>
> attachments_posts table:
>    attachment_id
>    post_id
>
> Models:
> class Post extends AppModel {
>     var $name = 'Post';
>     var $hasAndBelongsToMany = array(
>         'Attachment' => array(
>                 'className' => 'Media.Attachment',
>                 'joinTable' => 'attachments_posts',
>                 'foreignKey' => 'post_id',
>                 'associationForeignKey' => 'attachment_id',
>         )
>     );
> --------------------------------------------------------------------------------------
> class Attachment extends AppModel {
>
>         var $name = 'Attachment';
>         var $actsAs = array(
>                 'Media.Transfer' => array(
>                         'trustClient' => false,
>                         'baseDirectory' => MEDIA_TRANSFER,
>                         'destinationFile' => ':Medium.short::DS::Source.basename:',
>                         'createDirectory' => true
>                 ),
>                 'Media.Media' => array(
>                         'metadataLevel' => 2,
>                         'makeVersions' => true,
>                         'filterDirectory' => MEDIA_FILTER
>                 )
>         );
>
>         var $hasAndBelongsToMany = array(
>                 'Post' => array(
>                         'className' => 'Post',
>                         'joinTable' => 'attachments_posts',
>                         'foreignKey' => 'attachment_id',
>                         'associationForeignKey' => 'post_id',
>                 )
>         );
> ----------------------------------------------------------------------------------------
>
> This doesn't work: when i add a post it stores the post record in post
> table but it doesn't upload the attachment and saves the attachment
> record in the database...
>
> Sorry for my English.
> Many thanks.
> Biusso

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate