我有两张桌子:
surveyTemplateHeader
surveyTemplateQuestions
我想要做的是从两个表中获取信息:
var q = dao.getSurveyTemplateDetails( surveyTemplateID = ARGUMENTS.surveyTemplateID );
然后使用Coldbox使用查询数据填充我的模型surveyTemplate
:
var surveyTemplateObj = populator.populateFromQuery( beanFactory.getInstance("surveyTemplate"), q );
这样,然而,模型只会填充一个问题。我正在测试的调查模板有三个问题。
我尝试在我的模型中正确设置property name
以使用fieldtype="one-to-many"
,但这似乎没有什么区别。
property name="surveyTemplateQuestionID" fieldtype="one-to-many";
虽然Coldbox的整体模型文档非常好,但我无法找到答案,这可能意味着我在执行此操作时偏离了轨道。
任何见解都将受到赞赏。
答案 0 :(得分:0)
您可以循环查询以构建对象数组。 populateFromQuery方法接受查询行号以从查询中获取数据。
var surveyTemplateObj = [];
for(var row in q){
ArrayAppend(surveyTemplateObj, populator.populateFromQuery( beanFactory.getInstance("surveyTemplate"), q , row.currentRow));
}
答案 1 :(得分:0)
所以,我为此做的是将surveyTemplateQuestions
模型注入我的surveyTemplate
模型中:
property name="surveyTemplateQuestions" inject="surveyTemplateQuestions";
然后我用问题查询设置surveyTemplateQuestions
属性:
surveyTemplateObj.setSurveyTemplateQuestions(qQuestions);
不完全是我想要的,但它现在有效。