- There is a missing ' before category_id after 'associationForeignKey'
- Your conditions in the find->list look wrong; try 'conditions' => array('stock_id' => $this->Stock->id)
- The convention is to name your joining table CategoryStock (the two models are in alphabetical order). Although your arrangement ought to work, I generally stay with conventions unless there is a compelling reason not to.
- Do you have a model for StockCategory?
- What happens when you use find 'all' rather than 'list'?
- What happens when you die(debug($selectedRecord)) in your controller before passing it to your view?
Out of interest, what does the resulting SQL look like?
Jeremy Burns
Class Outfit
jeremyburns@classoutfit.com
http://www.classoutfit.com
On 27 Apr 2011, at 22:51, jackgoh wrote:
> Hi cricket,
>
> The $this->Stock->id is set correctly. And the SQL is working
> perfectly, i can get the correct number of records (which 3 of them:
> 4, 7, 14)
>
>
> On Apr 27, 1:53 am, cricket <zijn.digi...@gmail.com> wrote:
>> Is $this->Stock->id set to something? What does the SQL look like? Set
>> debug to 2 to see it.
>>
>>
>>
>> On Mon, Apr 25, 2011 at 1:25 PM, jackgoh <kockh...@gmail.com> wrote:
>>> Hi,
>>
>>> I am facing some problem when deal with a realtionship tables, the
>>> record is not display :
>>
>>> // in Stock model:
>>> var $hasAndBelongsToMany = array(
>>> 'Category' => array(
>>> 'className' => 'Category',
>>> 'joinTable' => 'category',
>>> 'foreignKey' => 'stock_id',
>>> 'associationForeignKey' => category_id',
>>> 'with' => 'StockCategory',
>>> ),
>>> );
>>
>>> // in Stock controller:
>>> $selectedRecord = $this->Stock->StockCategory->find('list',
>>> array( 'fields'=>array('stock_id','category_id'),
>>> 'conditions'=>array('stock_id='.$this->Stock->id) ) );
>>> $this->set(compact('selectedRecord'));
>>
>>> I try to copy the SQL by using debug() to phpmysql, and i get 3 lines
>>> of records. but when i try to PRINT_R the $selectedRecord, i can only
>>> get 1 record, example:
>>
>>> Array
>>> (
>>> [1] => 4
>>> )
>>
>>> Suppose the result have to be :
>>
>>> Array
>>> (
>>> [1] => 4
>>> [1] => 7
>>> [1] => 14
>>> )
>>
>>> Values : 4,7,14 are category_id, [1] is stock_id. There is a table
>>> call "category" to store all the category name.
>>
>>> Please point out whats wrong to my code or logic??
>>
>>> Thanks
>>
>>> Best Regards.
>>
>>> --
>>> Our newest site for the community: CakePHP Video Tutorialshttp://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
>>> cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php- Hide quoted text -
>>
>> - Show quoted text -
>
> --
> 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
> cake-php+unsubscribe@googlegroups.com 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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment