Thanks for the reply, Florin.

Auction hasMany AuctionImages is the way that it is currently set. The
problem is that it currently "uses up" any AuctionImage that is
associated with the Auction. Each image is associated with a
particular auction_id.

What I'm looking for is a way to have a set of images that I then
associate with numerous auctions. That is multiple images with
multiple auctions (e.g. 6 images for a single item type and then
associate them with multiple auctions).

In addition to the structure that I'm attempting in the Models, here
is the current structure of the database tables:

     auctions:
          Column                       Type
         1      id                      int(11)            (AUTO INCREMENT)
         2      title                   varchar(255)
         5      description     text
         6      category_id     int(11)
         ....
         26     created         datetime
         27     modified                datetime

        Keyname          Type         Unique      Column
        PRIMARY         BTREE   Yes             id
        category_id     BTREE   No              category_id

     auction_images:
         1      id                      int(8)          UNSIGNED        
AUTO_INCREMENT
         2      auction_id              int(11)
         3      image           varchar(255)
         4      order                   int(11)
         5      created         datetime
         6      modified                datetime

         Keyname       Type           Unique      Column
         PRIMARY              BTREE     Yes             id
         auction_id           BTREE     No              auction_id


     Join table - auctions_auction_images
         1     id                       int(11)      AUTO_INCREMENT
         2     auction_id           int(11)
         3     auction_image_id int(11)
         4     order                   int(1)

        Keyname                 Type            Unique    Column
        PRIMARY                 BTREE   Yes           id
        auction_id                      BTREE   No            auction_id
        auction_image_id        BTREE   No            auction_image_id

I hope this help clear up what I am looking for.

Thanks,
Sean

On Feb 15, 5:33 pm, Florin Trifu <[email protected]>
wrote:
> Hi
>
> I don't know if my understanding is correct, but Auction hasMany
> AuctionImages and not HABTM.
> You should try to change that hasAndBelongsTo from the Auction model, of
> which I've never heard by the way, into hasMany.
>
> As by the error following the pattern "model_name_X is not associated with
> model_name_X" usually appears in this case:
>
> Let's take for example you Image model:
>
> - you use $actsAs = array('Containable')
> - then you pass an array following this pattern into a query interrogating
> the Image model:
>
> array('contain' => array('Image' [,'model_name']))
>
> Hope it's useful!
>
> Best regards!
>
>
>
>
>
>
>
> On Wed, Feb 15, 2012 at 10:40 PM, Sean <[email protected]> wrote:
> > Hi all,
>
> > I am trying to do something that I think is pretty common.
>
> > I am working on an auction site and if I had say a auctions table and
> > a auction_images table. I want to be able to use multiple images with
> > multiple auctions.
>
> > In other words - auction1 be associated with auction_image 1, 2, 3 &
> > auction2 be associated with 1, 2, 3
>
> > When I use a $belongsTo relationship from Users to Images it works
> > fine, but that limits things to haveing specific images directly
> > linked to image id's (effectively "using up" the associated images).
>
> > I thought that the HABTM direction was the way to go, but am having a
> > problem with it.  But when I use HABTM, I get an error that the model
> > images is not associated with the model images. I believe that I have
> > followed the book.cakephp directions and Josh Benner's directions but
> > it's not working.
>
> > Here are the model's:
>
> >     Auction Model:
> >        class Auction extends AppModel {
>
> >                var $name = 'Auction';
>
> >                var $actsAs = array('Containable');
>
> >                var $belongsTo = array(
> >                        'Category' => array(
> >                                'className'  => 'Category',
> >                                'foreignKey' => 'category_id'
> >                        ),
> >                        'Status' => array(
> >                                'className'  => 'Status',
> >                                'foreignKey' => 'status_id'
> >                        ),
> >                        'Winner' => array(
> >                                'className'  => 'User',
> >                                'foreignKey' => 'winner_id'
> >                        )
> >                );
>
> >                var $hasMany = array(
> >                        'Bidbutler'  => array(
> >                                'className'  => 'Bidbutler',
> >                                'foreignKey' => 'auction_id',
> >                                'limit'      => 10,
> >                                'dependent'  => true
> >                        ),
>
> >                        'Bid' => array(
> >                                'className'  => 'Bid',
> >                                'foreignKey' => 'auction_id',
> >                                'order'      => 'Bid.id DESC',
> >                                'limit'      => 10,
> >                                'dependent'  => true
> >                        ),
>
> >                        'Autobid' => array(
> >                                'className'  => 'Autobid',
> >                                'foreignKey' => 'auction_id',
> >                                'limit'      => 10,
> >                                'dependent'  => true
> >                        )
> >                );
>
> >                var $hasAndBelongsTo = array(
> >                        'AuctionImage'   =>
> >                                array(
> >                                        'className'                  =>
> > 'AuctionImage',
> >                                        'joinTable'                     =>
> > 'auctions_auction_images',
> >                                        'foreignKey'                   =>
> > 'auction_id',
> >                                        'associationForeignKey' =>
> > 'auction_image_id',
> >                                        'unique'                        =>
> > false,
> >                                        'limit'
> >  => '6',
> >                                        'order'
> >  => array('order' => 'asc'),
> >                                ),
> >                );
>
> >     AuctionImages Model:
>
> >        class AuctionImage extends AppModel {
>
> >                var $name = 'AuctionImage';
>
> >                var $hasAndBelongsToMany = array(
> >                        'Auction' => array(
> >                                'className'                   => 'Auction',
> >                                'joinTable'                       =>
> > 'auctions_auction_images',
> >                                'foreignKey'                    =>
> > 'auction_image_id',
> >                                'associationForeignKey'  => 'auction_id',
> >                                'unique'                         => false,
> >                                'limit'                            => '6'
>
> >                        )
> >                );
>
> > I'm not sure how the controller language is supposed to look but an
> > example of the auction_image language would be:
>
> > $auction = $this->AuctionImage->Auction->read(null, $auction_id);
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
> >http://tv.cakephp.org
> > Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
> > others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group
> > athttp://groups.google.com/group/cake-php

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