Model setup help

Hi,

i am unsure what type of model relationship to setup. I have 2 tables ‘tests’ and ‘questions’.

I prefer to avoid habtm if possible. I have created a table with loads of questions and I want another table to contain a random 20 questions from the question table.

eg test table might contain questions for test1 with id’s 2,3,4, and test2 contains id’s 3,4,5.
each of the 20 questions in a test simply contains an id from the question table.

Thanks

Isnt this a habtm relationship ? Can I use a 1 to many some how as I really do not want to use a habtm .

if you have Tests.id and Questions.id, then you’ll need another table called Answers with composite primary key (test_id, question_id) and another field for the answer.

But i don’t think you always need to use habtm. Habtm is useful things like articles and tags, when articles_tags is only used to join tables.

In your case, you can use ‘tests has many answers’ and ‘answers belongs to questions and belongs to tests’

Hi, lets not worry about answers as this is in the questions table.

So it is ok to have a 1 to many relationship with test and questions?

Lets keep the argument simple with questions and test.
This is a many-to-many relationship isnt it as a question can be in different tests and a test can contain many questions
eg test1 has q1,q2
test2 has q2,q3

http://book.cakephp.org/3.0/en/orm/associations.html

where are my replies to this?