AnsweredAssumed Answered

How to grab a filtered list of related records to the current record in a custom module?

Question asked by aqua.alex aqua.alex on Jun 24, 2014
Latest reply on Jun 24, 2014 by aqua.alex aqua.alex
Again I have a very simple problem that should be easy to fix in theory but just not working for me. This problem appeared after updating from 6.0.x CE to 6.5.16 CE

In a special subpage of my module "ICC_TechGroups" all contacts that are related to this group are being loaded.

Old code looked like this:
$beanICC_TechGroups = new ICC_TechGroups();
$beanICC_TechGroups->retrieve($_REQUEST['record']); // loads TechGroup ID
$contacts = $beanICC_TechGroups->icc_techgroups_contacts->get();
Details to the relation (in database table "relationships"):
relationship_name: icc_techgroups_contacts
lhs_module: ICC_TechGroups
lhs_table: icc_techgroups
lhs_key: id
rhs_module: Contacts
lhs_table: contacts
lhs_key: id
join_table: icc_techgroups_contacts
join_key_lhs: techgroup_id
join_key_rhs: contact_id
relationship_type: many-to-many

In the old version contacts stored all ids of related contacts after get() was executed. In 6.5 it just stored the current "techgroup_id". To fix this I tried using the different examples ( or or ), but the results were either an empty Array or even an empty page.

An example would be when I tried to replace the last line ($contacts = ...) with
$contacts = array();
foreach ($beanICC_TechGroups->icc_techgroups_contacts->getBeans(new Contact()) as $contact) {
    $contacts[$contact->id] = $contact;
Does anyone have an idea on what the problem might be?