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