problem with get_entities_from_relationship

Hi to all and sorry for my bad english, i have a problem with elgg 1.7.1 and get_entities_from_relationship

i've got a relationship between users and a custom object buyers_group.

if i try to get the users of the group it's all ok (using elgg_get_entities_from_relationship(array('relationship' => 'member_of_treeboo_buyers_groups', 'relationship_guid' => $vars['entity']->guid, 'inverse_relationship' => TRUE, 'types' => 'user', 'limit' => 9999)); )

but if i try to get all the groups subscribed by a user i get nothing...

at the moment i use this

using elgg_get_entities_from_relationship(array('relationship' => 'member_of_treeboo_buyers_groups', 'relationship_guid' => get_loggedin_userid(), 'inverse_relationship' => FALSE, 'types' => 'buyers_group', 'limit' => 9999)); 

the strange thing is that even if i do a generic
elgg_get_entities_from_relationship(array('relationship' => 'member_of_treeboo_buyers_groups'));
i got no results... even if the first function i posted work fine and if i check the entity with check_entity_relationship ($user_guid, 'member_of_treeboo_buyers_groups', $group_guid) i got the relationship correctly...

can anyone please help me?

thanks in advance

Luca

  • Unless you've made some major core changes, the problem is that there are only 4 types of entities in Elgg: Object, User, Group, and Site.  You probably want:

    elgg_get_entities_from_relationship(array(

    'relationship' => 'member_of_treeboo_buyers_groups',

    'relationship_guid' => get_loggedin_userid(),

    'inverse_relationship' => FALSE,

    'types' => 'group',

    'subtypes' => 'buyers_group',

    'limit' => ELGG_ENTITIES_NO_VALUE  // use this to mean "no limit"

    ));

    Note the 'types' and 'subtypes' options.

  • Hi, thanks for your reply... 
    at the moment it still don't work... i've also made a patch to your code because buyers_group is an "object" and not a "group", but it still give no results...

  • After investigating i think it's a problem with the object type 'buyers_group',
    for example, if i execute this method

    elgg_get_entities_from_relationship(array(
    'relationship' => 'member_of_treeboo_buyers_groups',
    'inverse_relationship' => TRUE
    )); 

    wich return me a list of user, it works correctly, while if i execute this

    elgg_get_entities_from_relationship(array(
    'relationship' => 'member_of_treeboo_buyers_groups',
    'inverse_relationship' => FALSE
    )); 

    wich return me a list of buyers_group, it give me no results...
    i've defined buyers_group in this way:

    add_subtype("object", "buyers_group");
    register_entity_type('object','buyers_group');

    i'm doing something wrong???

    Luca

  • There is no type 'buyers_group.'  That is the subtype.

    It's difficult to help debug when we can't see how your code is creating these groups and relationships...

  • Hi, you are right! it's a misunderstand due to my bad english, sorry... :)

    by the way, after debugging the core elgg files i've found the problem.
    Elgg core function elgg_get_entities_from_relationship always do a join on the metadata table. my subtype buyers_group still have no metadata (it's in an early phase of development), so it give no results!!! i attach some metadata to it and all goes right! :)

    calling 

    elgg_get_entities_from_relationship(array(
    'relationship' => 'member_of_treeboo_buyers_groups',
    'inverse_relationship' => FALSE));

    produce the following query:

    SELECT DISTINCT e.* FROM elgg_entities e  JOIN elgg_entity_relationships r on r.guid_two = e.guid  JOIN elgg_metadata n_table on e.guid = n_table.entity_guid  WHERE  (r.relationship = 'member_of_treeboo_buyers_groups') AND  (e.site_guid IN (1)) AND ( (1 = 1)  and e.enabled='yes') ORDER BY e.time_created desc LIMIT 0, 10

    can it be considered a bug of elgg? if so, i'll post it...

    thanks for your patience!

    bye
    Luca

     

  • elgg_get_entities_from_relationship() does call elgg_get_entities_from_metadata() which seems unnecessary. Could you open a ticket in Trac for this: http://trac.elgg.org/ ?

  • Hi Cash,

    I think that if you want to have both relationship and metadata constraints on a query it is necessary.

    I'm pretty sure that one of my plugins counts on this current workflow in fact.

    I would hate it if we ended up introducing a new bug to fix the current problem.

    Isn't the actual problem that elgg_get_entities_from_metadata() does not work properly if no metadata is attached to an object?

     

  • I'm with Kevin here. I'm quite sure one of my plugins is also getting entities based on both metadata and relationship.

  • i agree too, if elgg_get_entities_from_metadata() could be fixed would be great, but at the moment, even if it's not a big problem, the behaviour of elgg_get_entities_from_relationship is inconsistent and this thing should be at least documented.