On Jun 2, 3:29 pm, Marcelo Andrade <mfandr...@gmail.com> wrote:
> On Mon, Jun 1, 2009 at 5:41 AM, Petter <petter.vegsund.bro...@gmail.com> 
> wrote:
>
> > Hello, all.
>
> > I have a model for image uploads. Each upload belongs to one other
> > model, such as Car or House. Currently, I solve this by using one
> > hasAndBelongsToMany for each model that has images, which works, but
> > is obviously not ideal.
>
> > I see at least two possible, but not pretty, solutions to this:
> > * Have car_id, house_id etc. in the images table, which leaves you
> > with a lot of null values.
> > * Have one model for each model that can have an image like this:
> > car_image, house_image, which makes for a lot of unnecessary models.
>
> If I undestood corretly and if your models has only one upload,
> the more adequate association should be that your models
> know their related upload.
>
> Did you try to put a foreignKey like upload_id in your Car, House
> models?  In this case your associations should be "Car belongsTo Upload"
> and "Upload hasOne Car", "Upload hasOne House" and so on.
>
> Best regards.
>
> --
> MARCELO DE F. ANDRADE
> Belem, PA, Amazonia, Brazil
> Linux User #221105
>
> http://mfandrade.wordpress.com

Sorry if I was vague: each model hasMany uploads (you can have three
pictures of the same car, for example). If they could only have one,
I'd solve it as you say.

Best regards,
Petter Brodin
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to