(sorry, i tried to be brief)
I'm trying to understand and use $hasAndBelongsToMany
So, i created this:
var $hasAndBelongsToMany = array('Conhecimento' =>
array('className' => 'Conhecimento'
,'joinTable' =>
'cli_resposta_conhecimento'
,'foreignKey' => 'curriculo_id'
,'associationForeignKey' => 'conhecimento_id'
,'conditions' => ''
,'order' => ''
,'limit' => ''
,'unique' => false
,'finderSql' => ''
,'deleteQuery' => ''
)
);
[Conhecimento] => Array
(
[0] => Array
(
[id] => 1
[categoria] => 1
[descricao] => Word
)
[1] etc etc etc
)
I'm following the tutorial explaining about hasAndBelongsToMany in Cake
manual but i was expecting a different result, like this:
[Conhecimento] => Array
(
[0] => Array
(
[id] => 1
[categoria] => 1
[descricao] => Word
[cli_resposta_conhecimento] => Array <- EXPECTING
THIS
(
[id] => 1
[curriculo_id] => 12
[conhecimento_id] => 1
[resposta_escolha] => 4
[resposta_descricao] =>
)
)
)
Briefing...
I look the generated SQL and i found this:
SELECT
`Conhecimento`.`id`, <- THIS FIELD
`Conhecimento`.`categoria`, <- THIS FIELD
`Conhecimento`.`descricao` <- THIS FIELD
// HERE SHOULD BE THE FIELDS OF OTHER TABLE
FROM `sis_conhecimento` AS `Conhecimento`
JOIN `cli_resposta_conhecimento` ON
`cli_resposta_conhecimento`.`curriculo_id` = 'blah' AND
`cli_resposta_conhecimento`.`conhecimento_id` = `Conhecimento`.`id`
WHERE 1 = 1
Result:
id categoria descricao
------ --------- -----------
1 1 Word
2 1 Excel
3 1 Power Point
To the point:
The statement i need, SHOULD have * in SQL command, like this:
SELECT
* <----- LIKE THIS
FROM `sis_conhecimento` AS `Conhecimento`
JOIN `cli_resposta_conhecimento` ON
`cli_resposta_conhecimento`.`curriculo_id` = 'blah' AND
`cli_resposta_conhecimento`.`conhecimento_id` = `Conhecimento`.`id`
WHERE 1 = 1
NOW, i have what i want:
id categoria descricao id curriculo_id conhecimento_id
resposta_escolha
------ --------- ----------- ------ ------------ ---------------
----------------
1 1 Word 1 12 1
4
2 1 Excel 2 12 2
1
3 1 Power Point 3 12 3
(NULL)
so... i had to dug the source code and i bacame sad discovering this
(line 252 in model_php4.php)
'hasAndBelongsToMany' => array(
'className',
'joinTable',
'fields', => LOOT AT ME! I'M NOT IN DOCUMENTATION!
'foreignKey',
'associationForeignKey',
'conditions',
'order',
'unique',
'finderQuery',
'deleteQuery',
'insertQuery')
i put * in the FIELDS and i solve my problem!
i could solved this 2 day ago if this sh** was documented.......
am i wrong? can somebody enlight me?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---