Thanks for the reply Brian.
Interesting thought on reversing the association, that would work
pretty well me thinks, but it doesn't follow the program logic.
Shouldn't something like this work...
$unansweredQuestions = $this->Question->findAll(array('Answer.id' =>
''));
It just doesn't.
On Jan 26, 10:17 pm, brian_gaff <[EMAIL PROTECTED]> wrote:
> >>Is this proper behavior? It seems like it should not return an Answer
>
> array at all.
>
> Yes. You can do something like
>
> if(isset($question['Answer']['id']))
> {
> /* do something with answer */
> }
>
> You might consider reversing it and putting the foriegn key in the
> questions table, and having each Answer haveOne question and each
> Question belongTo an answer. If you do that you can do:
>
> $questionsWithNoAns = $this->Question-
>
> >findAll(array('Question.answer_id' => 0));
>
> On Jan 25, 12:18 pm, Corie <[EMAIL PROTECTED]> wrote:
>
> > Using Cake 1.2, when I perform a findAll() on a model with a hasOne
> > association it's returning an array for the associated table even if
> > there is no record.
>
> > Here's an example.
>
> > // question.php
> > class Question extends AppModel
> > {
> > var $name = 'Question';
> > var $hasOne = 'Answer';
>
> > }
>
> > // answer.php
> > class Answer extends AppModel
> > {
> > var $name = 'Answer';
> > var $belongsTo = 'Question';
>
> > }
>
> > // questions_controller.php
> > class QuestionsController extends AppController
> > {
> > function index()
> > {
> > $questions = $this->Question->findAll();
> > pr($questions);
> > }
>
> > }
>
> > // outputs
>
> > Array
> > (
> > [0] => Array
> > (
> > [Question] => Array
> > (
> > [id] => 4
> > [question] => why?
> > [created] => 2008-01-25 00:23:44
> > [ip] => 192.168.0.101
> > )
>
> > [Answer] => Array
> > (
> > [id] =>
> > [question_id] =>
> > [answer] =>
> > [created] =>
> > [name] =>
> > )
> > )
> > )
>
> > Is this proper behavior? It seems like it should not return an Answer
> > array at all.
>
> > Anyways, another question is, how would I go about finding only
> > questions which do not have answers?
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---