Hi there, fairly simple usage question - I can't find anything on how to get a Relation field in Views. I've looked through the readme and concepts files, through the issues and done as much trial and error in views as I can think of.
Simple example use case: a relation type 'Recommended' with a field 'Rationale', and a views block 'Recommended content' which, on the page for node X, for each node with a 'Recommended' relation from node X, shows:
-- The node title with a link to the recommended node Y (easy using a relationship)
-- The 'Rationale' text field from the relation itself, explaining this particular node-node relationship. This is the thing I can't see how to do.
E.g. if it was a recipe site:
Spam Casserole
--------------
...node content...
Other recommended dishes
* Double spam casserole Same pan, double the spam
* Lamb casserole For those who aren't fans of the spam
* Yam casserole Our closest vegetarian alternative
There's nothing about relations that I can see in Views fields, filters or contextual filters that would retrieve the field content from the relation itself.
Can this be done yet? I see from #1242824: Populate a field attached to a relation during relation creation. (And additional ideas) that some elements of relation fields are a work in progress. If it can, what am I missing?
Using latest dev (as of 17th Aug 2011), and I have an existing relation of the appropriate type with the appropriate field saved.
Thanks!
Comments
Comment #1
ofridagan commentedsubscribing
Comment #2
Daniel _Bun commentedYes I exactly face this problem also ... I cant figure out where can show that
The 'Rationale' text field from the relation itself, explaining this particular node-node relationship. This is the thing I can't see how to do
This is what I thought the major two functions that can use .... what if one entity embed another entity , or even more...?
( I just know how to use connect two entity with each other with content title.....)
helpppppppppppppp
any tutorial example....on views work on "relation" module....thzzz
Comment #3
alanom commentedI'm glad to see this isn't just me being dense and missing something obvious...
I've tried updating to the latest Views dev, and I've had a debugging session looking through the code in modules/relation/views. I'm no views expert, but it's starting to look like this is a missing feature rather than missing documentation - I can't see anything in the code that looks like it would retrieve the relation field data.
Comment #4
alanom commentedI'm no expert on Entity API either, but it looks like we're missing something that cycles through fields and declares them to Entity API in relation_entity_property_info() in relation.module around line 76 as per the entity API views integration docs
Looks like this shouldn't be too hard to implement, but it's beyond my knowledge of how Entity API and Views work under the hood.
Comment #5
naught101 commentedYeah, missing feature. Relations aren't stored as fields, but separate entities. We haven't gotten around to implementing this yet. Will do soon.
Comment #6
chx commentedThe problem is, how to tell Views , this is an entity which has fields. Can't be too hard.
Comment #7
chx commentedIt wasn't. However, it's incomplete because it is done only for source bundles. So keeping active. And needs tests.
Comment #8
alanom commentedGreat fast response, but I can't see [***EDIT***] aha, I see how this works now.
As well as the [source/target]entity->-[target/source]entity views relationship, you add an additional views relationship, [source]entity->-relation, and that provides the fields. Makes sense. Will try it out later.
Comment #9
chx commentedI could enforce people to add two relations , one for the relation table and the from there the other endpoint entity base table but that'd be way too ugly :/
Comment #10
rlmumfordKind of related to this, I would like to make a view of all relations of a particular type, but I can't seem to make a view of relation entities. Is this going to be built in?
I'm using relation to collect a load of information about a contact so there is a relation between profile2's, potentially a user, and potentially a load of other types of entity. If I want to list all of these relations and have access to the fields of the profile2's the user and other entities, how would I do it?
Also, if I had a donation relation with an amount field, that linked a contact to a organization and stored how much was donated and I wanted to list all donations, regardless of who donated or who recieved the donation, how could I achieve this?
Comment #11
chx commented#10 there's a separate issue for that.... I will commit that later this week.
Comment #12
rlmumfordthanks chx!
Comment #13
alberto56 commentedSubscribing, thanks.
Comment #14
itangalo commentedIt is now possible to:
* Add Views relationships from entities to related entities
* Add Views relationships from entities to relations
* Make a view of relations (see #1260236: Provide proper views integration for the relation base table. for patch to be committed)
* Get information about how to do this (see for example http://nodeone.se/node/970, screencasts 5–7)
It is not yet possible to add relations to *both* relations and the related entities without getting duplicates – see #1260252: View relationship "relation -> entity".
Closing this issue!