Hello,
I have the scenario with people table and many-to-many relationships between them (friends):
Table person (id, name, primary key(id))
Table person_friends (id, friend_id, primary key(id, friend_id))

In order to list all friends of a person I do the join:
SELECT name FROM person, person_friends WHERE person.id=person_frields.friend_id AND person_friends.id=100

To get list of all people who addded another person as a friend, I need:
SELECT name FROM person, person_friends WHERE person.id=person_frields.id AND person_friends.friend_id=100

In my Views data definition I am able to declare "friends" base table that joins to the "person_friends" either with "person_friends.id" or "person_friends.friend_id" field, but not both:

$data['person']['table']['join'] = array(
        'person_friends' => array(
            'left_field' => 'id',
            'field' => 'id',
        ),
    );

//OR

$data['person']['table']['join'] = array(
        'person_friends' => array(
            'left_field' => 'friend_id',
            'field' => 'id',
        ),
    );

But in order to do both fiend and friend-of queries I have to declare both these relationships.

Is it possible to do with Views2? I suppose that it is necessary to write custom join handler, but there is not much documentation on that.
Thank you in advance.

Comments

dawehner’s picture

I think you can give the join a random name and define left_table.

alternative it would make sense to use a relationship to be more flexible. See friendlist as example.

rschwab’s picture

Status: Active » Fixed

Marking as fixed. Feel free to open again if you need more help.

Status: Fixed » Closed (fixed)
Issue tags: -join

Automatically closed -- issue fixed for 2 weeks with no activity.