Well, the most direct answer:

Items belongsTo Types
Types hasAndBelongsToMany Questions
Questions hasAndBelongsToMany Answers
(you can add relations in the other direction, too)

Then when you retrieve an item, you would need recursive=3, and you'd 
have access to all the data in an array following the association hierarchy.

Now, I don't know the specific application you're working on, but my 
instinct suggests that you might not want to be pulling every question 
for each type that any given item is related to. So I would pull items 
with recurisve=1, provide links to the types, and pull types one at a 
time based on user input with the appropriate recursive setting for the 
display you want to generate.

Remember to try not to pull way more data than you will use or display, 
and don't define associations just for the heck of it if you're not 
going to use them. Also remember two-way associations can be weird with 
higher recursion settings, causing a lot of extra queries to the database.

If you would like to describe your application and the target interface 
a little, maybe we could help you narrow down your implementation options.


Joey wrote:
> Ok here is the scenario.
>
> There will be "Items" that are of a "Type" and each "Type" has it own
> "Questions" and the "Questions" have their own "Answers".  So how do I
> store the "Answers" chosen for each "Question" for each "Item".
>
> The table structure so far is below.  Let me know if this doesn't make
> sense, or if I am going about this wrong.
>
> Thanks,
> Joey
>
> CREATE TABLE `items` (
>   `id` int(11) NOT NULL auto_increment,
>   `type_id` int(11) NOT NULL,
>   `title` varchar(255) default NULL,
>   `description` mediumtext,
>   `date` datetime NOT NULL,
>   PRIMARY KEY  (`id`),
>   KEY `type_id` (`type_id`)
> )
>
> CREATE TABLE `types` (
>   `id` int(11) NOT NULL auto_increment,
>   `name` varchar(100) NOT NULL,
>   PRIMARY KEY  (`id`)
> )
>
> CREATE TABLE `questions` (
>   `id` int(11) NOT NULL auto_increment,
>   `question` mediumtext NOT NULL,
>   PRIMARY KEY  (`id`)
> )
>
> CREATE TABLE `answers` (
>   `id` int(11) NOT NULL auto_increment,
>   `answer` mediumtext NOT NULL,
>   PRIMARY KEY  (`id`)
> )
>
> CREATE TABLE `answers_questions` (
>   `answer_id` int(11) NOT NULL,
>   `question_id` int(11) NOT NULL,
>   `order` int(11) default NULL,
>   PRIMARY KEY  (`answer_id`,`question_id`)
> )
>
>
> CREATE TABLE `questions_types` (
>   `question_id` int(11) NOT NULL,
>   `type_id` int(11) NOT NULL,
>   `order` int(11) default NULL,
>   PRIMARY KEY  (`question_id`,`type_id`)
> )
>
>
> >
>   


 
-- 
Joshua Benner
http://bennerweb.com


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

Reply via email to