# Model setup help

**URL:** <https://discourse.cakephp.org/t/model-setup-help/444>\
**Category:** Need Help\
**Created:** [June 2, 2016, 1:51am UTC](https://discourse.cakephp.org/t/model-setup-help/444 "2016-06-02T01:51:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewet](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@andrewet](https://discourse.cakephp.org/u/andrewet)\
**Post date:** [June 2, 2016, 1:51am UTC](https://discourse.cakephp.org/t/model-setup-help/444/1 "2016-06-02T01:51:09Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![alysson\_azevedo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/alysson_azevedo/32/194_2.png) [@alysson\_azevedo](https://discourse.cakephp.org/u/alysson_azevedo)\
**Post date:** [June 2, 2016, 4:32am UTC](https://discourse.cakephp.org/t/model-setup-help/444/2 "2016-06-02T04:32:43Z")

</div>

if you have [Tests.id](http://Tests.id) and [Questions.id](http://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’

---

<div class="post-metadata">

**Author:** ![andrewet](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@andrewet](https://discourse.cakephp.org/u/andrewet)\
**Post date:** [June 2, 2016, 5:29am UTC](https://discourse.cakephp.org/t/model-setup-help/444/3 "2016-06-02T05:29:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![andrewet](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@andrewet](https://discourse.cakephp.org/u/andrewet)\
**Post date:** [June 2, 2016, 5:35am UTC](https://discourse.cakephp.org/t/model-setup-help/444/4 "2016-06-02T05:35:44Z")

</div>

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](http://book.cakephp.org/3.0/en/orm/associations.html)

---

<div class="post-metadata">

**Author:** ![andrewet](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@andrewet](https://discourse.cakephp.org/u/andrewet)\
**Post date:** [June 4, 2016, 1:44pm UTC](https://discourse.cakephp.org/t/model-setup-help/444/5 "2016-06-04T13:44:59Z")

</div>

where are my replies to this?
