public function getModuleRelationships($module, $type = 'all')
    {
        // Check in cache
        if (isset($this->moduleRels[$module][$type])) {
            $this->getLogger()->debug($this->logPrefix . 'Got rels for this module in cache');

            return $this->moduleRels[$module][$type];
        }

        $sugarBean = $this->getBean($module);

        $data = array();
        $rels = $sugarBean->get_linked_fields();
        // removing the "right side" of a relationship
        foreach ($rels as $props) {
            $relName = $props['relationship'];

            $relationship = new \Relationship();
            $relationship->retrieve_by_name($relName);
            // Id is empty: fake relationship, especially for users
            if (empty($relationship->id)) {
                continue;
            }
            // Just rename the relationship if I ask only the beans directly related
            if ($type == 'one' &&
               (array_key_exists('side', $props) && $props['side'] == 'right'
               || array_key_exists('link_type', $props) && $props['link_type'] == 'one')
            ) {
                $relName = $props['name'];
            }

            // I am in a many to One, ignore other
            if ($type == 'one' && $relName == $relationship->relationship_name) {
                continue;
            }

            // Write data
            $data[$relName] = array(
                'relationship_name' => $relName,
                'lhs_key' => $relationship->lhs_key,
                'lhs_module' => $relationship->lhs_module,
                'relationship_type' => $relationship->relationship_type,
                'rhs_module' => $relationship->rhs_module,
                'rhs_key' => $relationship->rhs_key,
                'join_table' => $relationship->join_table,
                'join_key_lhs' => $relationship->join_key_lhs,
                'join_key_rhs' => $relationship->join_key_rhs,
            );
        }
        // sort it
        ksort($data);
        // cache it
        $this->moduleRels[$module][$type] = $data;

        return $data;
    }