HABTM vs hasMany depends on your application functionality - between
an article and an image is it hasMany (each image is only in one
article), or HABTM (each image could be in multiple articles)?  The
table setup will follow these application requirements, not the other
way round.

If you can have a single table, do it.  I would recommend each Image
having a field "foreign_model" and "foreign_id", and the association
from Article would be:

        var $hasMany = array(
                'Image' => array(
                        'className' => 'Image',
                        'conditions' => array(
                                'Image.foreign_model'=>'Article',
                                'Image.is_archived' => 0
                                ),
                        'foreignKey' => 'foreign_id',
                        'dependent' => true,
                ),
        );

This way the one Image table can store images used for any other
associations.


On Sep 22, 9:57 am, bigbass <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> I'm setting up a new site with cake 1.1. As a cake-newby, maybe you
> could give me your 5 cents (or even more? :) :
> The site uses user-generated images in different places (user profile,
> galeries, articles etc)
> I'm thinking of setting up just one table which stores image
> information (meta's etc) and joining this table via HABTM (eg.
> articles_images to the refering table articles). Is this a good
> practice in cake, or in general? Or would it be more efficient (and
> more resource-friendly) to use separate tables for each referer, as a
> HasMany relation (articles HasMany articleImages). Which models would
> be faster concerning requests?
>
> Best regards,
> thanks for your cents in advance,
> Benjamin


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

Reply via email to