1

I have two tables:

surveyTemplateHeader
surveyTemplateQuestions

What I was looking to do was get the information from both tables:

var q = dao.getSurveyTemplateDetails( surveyTemplateID = ARGUMENTS.surveyTemplateID );

Then use Coldbox to populate my model, surveyTemplate, with the query data:

var surveyTemplateObj = populator.populateFromQuery( beanFactory.getInstance("surveyTemplate"), q );

This works, however, the model is only populated with one question. The surveyTemplate I am testing has three questions.

I have tried to set up a property name correctly in my model to use fieldtype="one-to-many" but that does not appear to have made a difference.

property name="surveyTemplateQuestionID" fieldtype="one-to-many";

While Coldbox's documentation for models overall is quite good, I am not able to find an answer for this, which probably means I am off track a good bit in my implementation of this.

Any insight would be appreciated.

Caleb Palmquist
  • 448
  • 2
  • 7
  • 15

2 Answers2

1

So, what I did for this is I injected a surveyTemplateQuestions model into my surveyTemplate model:

property name="surveyTemplateQuestions" inject="surveyTemplateQuestions";

then I set the surveyTemplateQuestions property with the questions query:

surveyTemplateObj.setSurveyTemplateQuestions(qQuestions);

Not exactly what I was looking for but it works for now.

Caleb Palmquist
  • 448
  • 2
  • 7
  • 15
0

You can loop over query to build Arrays of objects. populateFromQuery method takes query row-number to get data from query.

var surveyTemplateObj = [];

for(var row in q){
    ArrayAppend(surveyTemplateObj, populator.populateFromQuery( beanFactory.getInstance("surveyTemplate"), q , row.currentRow));
}

API Doc info http://apidocs.ortussolutions.com/coldbox/4.3.0/coldbox/system/core/dynamic/BeanPopulator.html#populateFromQuery()

Sana
  • 61
  • 1
  • Thanks for your comment Sana. I am actually doing this in another part of the code for the Survey Template listing page. The difference there is I only need the information in the header table. I am wanting to have an object represent a complete survey template, with all of its questions as well. If I were to loop over the query and create an array of question objects, would I be able to "merge" that somehow into the template object with the header information? Thanks! – Caleb Palmquist Jan 17 '17 at 13:33