This issue is extending of the question(s) by the link joomla.stackexchange.com/a/9836/4042 but with condition when child record has not only ONE parent (parent record) but MANY.
With two left joins from the accepted answer by that link it works perfectly if child record has only ONE parent (or many childs are bound to the same ONE parent). But what about the case when one child record is bound to multiple parents (parent records)? I.e:
id name 1 Child1 2 Parent1 3 Parent2
id child_id parent_id 1 1 2 2 1 3
Using that two left joins for this case I get the same child record twice in the list of records at the back-end for each parent_name:
ID CHILD PARENT 1 Child1 Parent1 1 Child1 Parent2
So there are two questions:
1. How to push the parent_name to array() and to get the list of child records at the back-end of my component (if administrator/index.php?com_mycom&view=recordS) like:
ID CHILD PARENT 1 Child1 Parent1, Parent2
2. How to get the field with array of parents in the form for editing a single record and how to (re)save the field in the DB (if administrator/index.php?com_mycom&view=record&layout=edit&id=1)? I try to add to my admin/models/forms/record.xml the field like:
<field name="parentheader" type="list" label="COM_MYCOM_PARENT" description="" class="chzn-color-state" multiple="multiple"> <option value="0">COM_MYCOM_SELECT_PARENT</option> </field>
and to render it in tmpl with this one:
JHtml::_('formbehavior.chosen', 'select'); ... <div class="control-group"> <div class="control-label"> <?php echo $this->form->getLabel('parentheader'); ?> </div> <div class="controls"> <?php echo $this->form->getInput('parentheader'); ?> </div> </div>
But I get this output:
It must be like the field for categories in the product editing panel of Virtuemart where I can bind a product to many categories:
What code should I add to my admin/models/forms/record.xml and admin/models/record.php (or to JTable class)?