Re: Only show data which isn't in the other table. (complex).
@euromark You're absolutely right. I should avoid doing anything cerebral after midnight when I'm exhausted but unable to sleep--the synapses didn't fire all the way. :-D -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Only show data which isn't in the other table. (complex).
@shadow why so complicated - i would just pass along the array: array('NOT' => array('Survey.id' => Set::extract('/SurveyUser/id', $answered On 7 Mai, 08:15, Dwayne Hanekamp wrote: > Awesome! > > I would like to thank you both! :) > > Dwayne -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Only show data which isn't in the other table. (complex).
Awesome! I would like to thank you both! :) Dwayne -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Only show data which isn't in the other table. (complex).
If: Survey hasMany SurveyUser User hasMany SurveyUser SurveyUser belongsTo Survey SurveyUser belongsTo User with ContainableBehavior (see: http://book.cakephp.org/view/1323/Containable), you can try something like the following in your controller: // Get list of all surveys, and any responses the user has made to the surveys $surveys = $this->Survey->find('all', array( 'contain' => array( 'SurveyUser' => array( 'conditions' => array( 'SurveyUser.user_id' => $user_id ) ) ) )); The resulting array will be all the surveys, with a sub-array (index name is 'SurveyUser'). If the user has not answered the survey, the sub-array will be empty, but the surveys the user has answered will also have a one-element sub-array containing the corresponding SurveyUser row for that user (and you can use that to "grey-out" the survey record on your view). If you prefer to completely exclude the surveys that the user has answered, you can always do something like: // Get list of surveys user has answered $answered = $this->Survey->SurveyUser->find('all', array( 'conditions' => array( 'SurveyUser.user_id' => $user_id ) ); // Get list of all surveys, excluding the ones answered by the user $surveys = $this->Survey->find('all', array( 'conditions' => array( 'Survey.id NOT IN (' . join(',', Set::extract('/SurveyUser/id', $answered)) . ')' ) ); Set::extract (see: http://book.cakephp.org/view/1501/extract) is used to convert $answered to a simple array of just the ids of the SurveyUser records. Or you can combine both using method outlined in http://book.cakephp.org/view/1030/Complex-Find-Conditions, under the section "Sub-queries". For more information on the model relationship types, see http://book.cakephp.org/view/1039/Associations-Linking-Models-Together -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Only show data which isn't in the other table. (complex).
Dwayne, One simple way you could do this: Query Surveys to get the full set of possibles. Query SurveysUsers to get the completed set for the user. As you output the choices to the web page, loop through the full set array and check each one to see if it also exists in the completed set array. If yes, make grey. If no, make link (or whatever). Regards, Don On May 5, 2:15 pm, Dwayne Hanekamp wrote: > Hey all, > > I'm currently building a webapplication on which people fill in > surveys. My problem currently: I want surveys which are already filled > in to show up grey. I have two database tables: Surveys / SurveysUsers > in the first one are all the available surveys. In the second are all > records about surveys which users filled in. My problem currently: > Combining both tables with eachother to filter out the surveys which > the current user already filled in. > I've tried to search an answer for it but its kinda complex to google > something like this. I hope you guys can help me out! > > Cheers, > > Dwayne -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Only show data which isn't in the other table. (complex).
Hey all, I'm currently building a webapplication on which people fill in surveys. My problem currently: I want surveys which are already filled in to show up grey. I have two database tables: Surveys / SurveysUsers in the first one are all the available surveys. In the second are all records about surveys which users filled in. My problem currently: Combining both tables with eachother to filter out the surveys which the current user already filled in. I've tried to search an answer for it but its kinda complex to google something like this. I hope you guys can help me out! Cheers, Dwayne -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php