Closed (outdated)
Project:
Organic Groups
Version:
7.x-1.3
Component:
Og Views
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Aug 2011 at 14:33 UTC
Updated:
8 Dec 2025 at 00:41 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
nagiek commentedI'd like to do the same thing. To me, the relationships seem obvious, but I don't think views can recognize them.
Comment #2
henrijs.seso commentedSame here. Would like to list group posts and group entity titles in same table.
Comment #3
henrijs.seso commentedThis issue states that it is possible... #1006860: Allow views 'relationships' from group to group type and from group content type to group Will try to test, but I'm sceptical since I have tried to do it for 3 hours :)
Comment #4
nagiek commented@mansspams
The issue here is that the relationship is one-way. You can get the group from the entity, but you cannot get the entity from the group. For most people, it's probably not a problem unless they need to go from group to node to group in their relationships (like me, urgh :$)
If you check the og page, there's a video by bjlewis2 on how to do what you want. It's a great walkthrough.
Linking again for convenience. http://modulesunraveled.com/organic-groups
To me though, it seems like this issue is going to be postponed until a general Entity API solution is found. I would check the issue queue there for progress.
Comment #5
henrijs.seso commentedI was thinking that if there is a database table where both values are in same row, there should not be big problem to create relationships both ways and there is table 'og_membership' with all the info needed. How I wish I could write code better :(
Comment #6
amitaibu@mansspams,
Can you show a short table of the data you want to present, as example, to better understand you needs.
Comment #7
henrijs.seso commentedI have a view listing group post node titles in column A and I want to add column B with group node titles. How to set up relationships for this view? In perfect world from group post node I would make relationship #1 to group and relationship #2 to group node. In result I would be able to add title (or any other field from group node) and just select last relationship in display settings and views would display it in column B. All this should happen without Contextual filters.
Without it I have to do terrible things and kill kittens (like writting
$result = db_query("SELECT etid FROM {og} WHERE gid = :gid", array(':gid' => trim($content['gid'])));where $content['gid'] is HTML outputted by views) in theme just to demonstrate og in site ;)Comment #8
henrijs.seso commentedHere is visualization of that table...
Comment #9
nagiek commentedAh, then yes, you have the same node -> group -> node problem as me.
@Amitaibu
This would be a bit of work, but why not create a dependency using Relation (http://drupal.org/project/Relation) an Entity Reference Field (http://drupal.org/project/ref_field) to build the relationships? Seems like it would save you effort in the long run, since OG Views would become obsolete.
Comment #10
karens commentedI'm stuck here too and the ability to do a view of group content that includes both the group page node and the 'parent' group node seems like an obvious need. I have a 'group' content type that is the group entity. I have pages in the groups that are other content types. I need to display some information from the 'group' in a view of the pages. In this particular case, the group has an image field and I want that image displayed in a view of the group pages. The only workaround I've come up with is to go into the node view using hook_preprocess_node and add information from the parent group to the $variables, then create a custom node template that displays them. But that is a lot of work and it doesn't help on a view of fields, which is what I really need. This was easy to do in D6, so it feels like a regression that it can't be done in D7.
Not sure how to solve the problem though. It feels like the 'og' relationship should behave like the nodereference field relationship to join in the tables we need and make them available as sources for fields and filters, so you can say you want to see the title or some other field from the group entity brought in by the OG relationship.
Comment #11
jody lynnAfter fighting for hours with all the relationships, I'm relieved to hear it's not just me.
Comment #12
tim.plunkettNot sure if this is still a support request, but leaving for now.
Comment #13
amitaibu> This was easy to do in D6, so it feels like a regression that it can't be done in D7.
Indeed. This is because, unlike D6, OG group and OG membership are different entities. I think what is missing is a reverse relationship, (i.e. get node from group) -- it probably should go in og_views_data_alter(), although the best thing would have been able to get this automatically via entity-metadata - maybe improving #1066398: Reverse entity relationships for Views integration
Comment #14
skyredwangyeah, the current D7 OG Views integration is much less powerful than the D6 one. Therefore, I change the issue to feature request.
Comment #15
karens commentedI was thinking the same thing, a variation of views_handler_relationship_entity_reverse. We can't use that because it is very field-specific, but something like that to bring the reverse relationships into a view is what we want I think. I poked around with it but didn't get anything actually working. The code to look at as an example is in Views, in views/modules/field/views_handler_relationship_entity_reverse.inc.
Comment #16
karens commentedOr yes, somehow getting this automatically through Entity API. But I wasn't able to figure out what was needed there either :(
Comment #17
nagiek commentedI created an issue in Entity API. See the response here: #1288844: Merge Relation with Entity API. Is there a proper implementation of entity-property-info in OG?
Comment #18
CarbonPig commentedsubscribe
Comment #19
mortendk commentedsub
Comment #20
nagiek commented@Amitaibu
Since #1066398: Reverse entity relationships for Views integration was committed, any chance of seeing the effects in OG?
Comment #21
casey commentedRan into this issue too while upgrading a - D5, skipping D6 :) - site.
/Edit
Getting this to work is actually pretty tricky. Any entity type can potentially be a group. Entity types have their own base table however, so a simple reverse relationship isn't going to work.
/Edit
Or maybe it does. just add relationships for every entity type that is a group (has a group field).
Comment #22
casey commentedSomething like this? In most cases you need to setup multiple relations for it to be useful.
Comment #23
nagiek commentedAlso, if anyone is interested in a temporary hack, here's the relationship code for Group to Node only. Paste it in og.views.inc in the og_views_data_alter() function after
Temporary code:
Would always prefer to have Entity API take this over.
Comment #24
nagiek commentedwhoops. I guess we decided to fix this at the same time! I like the $is_group_type check.
Comment #25
bjalford commentedtested patch in #22 and worked fine.
Comment #26
les limBriefly tested #22 in a simple environment with only a single group type - worked fine for both User membership views and Node membership views. Haven't tested any more complex configurations. Nice work!
Structurally, I don't see any reason why we couldn't place the relationship definition within the foreach loop.
Comment #27
amitaibuThanks casey.
Instead of this check you can use og_get_all_group_entity().
Maybe: Relate an entity to its group entity.
Comment #28
nagiek commentedWe should do the same thing for group membership info too. Might be a bit harder because you can have both nodes and users.
Comment #29
holtzermann17 commentedI'm sorry to say I don't think the patches are working for me. I keep getting "There is no content in this group."
Comment #30
wjaspers commented#22 works for me.
Look for a relationship on the "group membership" relationship with a "TODO" description.
Then you can add arguments or fields as needed from the source entity.
Comment #31
tim.plunkettReroll of #22 with the feedback from #27.
Comment #32
penguininja commentedThe patch in #31 works for me. For others trying to reproduce, these were the steps I followed:
The result was that I could feed the view a group id and get the group node entity in return. Thanks!
Comment #33
amitaibuCommitted, thanks.
I wonder if it helps achieving #8, though.
Comment #34
willkaxu commentedIt seems too hard to tell views the "GID". Glad to see the patch, I will try it asap.
Comment #36
pdcarto commentedThis has saved my bacon, big time! Thank you so much @casey and @tim.plunkett!!!
Comment #37
nagiek commentedCan we add the membership->user relationship too?
Comment #38
restyler commentedThat's super cool addition to og, but it required me 1 hour to figure out how to fetch og group title, taking into account my 5 year experience with views
(I was building very simple view: group post title / group title - but I needed to list posts only from groups of node type "corporate blog" )
I had to enable views sql debug to figure out the final mix of relationships:
1) OG membership: OG membership from Node
2) (OG membership from node) OG membership: OG group gid
3) (OG group) OG group: Node from OG group
I hope that helps somebody who finds the topic.
may be it's just not my day, but I really think this is something impossible for ordinary user to figure out without step-by-step manuals.
Comment #39
skyredwangwell, for the advanced usage like this, the site builder needs to understand database. It's not built for ordinary users.
Comment #40
Saoirse1916 commentedIs there any way to use the method in #38 to get additional fields from the group? I've created my groups such that I'm using a building ID for the group title, then an additional field called Building Name. I'd like to get both fields into my view, but this method only exposes the building ID in the form of (OG group) OG group: Label.
The odd part is that in the list of Content fields both Content: Group and Content: Building Name fields are available even without the relationship. However, neither of them actually display any data (with or without the relationships).
Comment #41
jferrervalls commentedThank you "restyler" for your method in ( #38).
Your relationship chain worked fine for me.
I've been trying to do that all day long and was really starting to doubt it was possible in the views UI.
Thanks for sharing
Comment #42
robwithhair commented#31 worked for me although my relationships looked like this.
Group membership: Node group membership
(group membership) OG membership: Group gid
(OG group) Group: Node being the group
Comment #43
juan.pinedaf commented#31
Worked for me.
We have companies content type set as groups and then diff entities linking to the groups.
I needed to show in a view a table with content from the company node + article node
So now I'm able to set the relationship from my article all the way up to the group and also get the group node information, then I can set the fields as being from the company instead of from the article content type.
My relationships:
Group membership: Content group membership
(group membership from article doc) OG membership: Group gid
(OG group company where article belongs) Group: Content being the group
Thank you again guys!
Comment #44
liquidcms commentedhas this gotten lost/broken in 2.x?
i simply want to know the group my post is located in. i no longer see Group: Node relationships but do have Entity Relationships like: A bridge to the Content entity that is referenced via og_group_ref
but this doesn't seem to do anything.
Comment #45
DruDoc commented@liquidcms
Can you please provide some more information.
In 2.x the views setting will look like this:
Contextual filters
(Group node from OG membership) Content: Nid
Relationships
OG membership: OG membership from Node
(group membership) OG membership: Group Node from OG membership
Comment #46
DruDoc commentedNo bug
Comment #47
liquidcms commented@DruDoc, yes, that's part of the trick, thanks.. didn't realize that since going to 2.x the relationships are now hierarchical? so don't see the 2nd set until i add OG membership: OG membership from Node
also, for the case i was asking about... how to know a group content node's group node, i think the contextual filter part is just:
Content: Nid
not:
(Group node from OG membership) Content: Nid
since i am on the node not the group.
but, this still isn't complete if i want to recreate the simple block that came with D6 which is list group content creation links "within" a group since this only works on group content nodes; doesn't work on the actual group node itself.. i guess i need an OR in here somewhere.
and of course i'd still need a way to list all content types that can be added to a group.. ugghh.. probably still just easier to do this in code (and replicate the code that came with D6)
i am sure i am still getting accustomed to D7 OG; but wow.. this sure is much more convoluted than in D6.
i'll leave this as fixed as this was original question i believe and i do see now "how to get group from a group content node"; but real question should have been simply; how to tell group context? (which in D6 was known on group content or the group node itself)
Comment #48
liquidcms commentedso, is the "bug" here simply that this relationship: OG membership: OG membership from Node fails on the Group node?
in other words should the group node not be a member of the group?
Comment #49
DruDoc commentedThe screenshot might help :)
Comment #50
liquidcms commentedsince this works for group content nodes (but not group nodes); i'll raise a separate issue for that.
Comment #51
jferrervalls commentedI was using #38 relationship chain succesfully until something broke :
1) OG membership: OG membership from Node
2) (OG membership from node) OG membership: OG group gid
3) (OG group) OG group: Node from OG group
I now have the following error in the views UI:
1) OG membership: OG membership from Node
2) (OG membership from node) OG membership: OG group gid
3) (Groupe OG) Broken/missing handler
For some reason the 'Node from OG group' relationship does not appear in the list anymore.
I know someone else has made changes on that site (maybe a og update, it's now 7x-1.3 version in used )
Does someone knows witch version of OG GROUP I should use to find this relation back ?
Comment #52
MauPalantir commentedSame problem here....
Comment #53
spacereactor commented#45 can't get it to work in content pane. Any help? My goal is to display a list of other group content posts under the same group when viewing a group content.
using og 7.x-2.x-dev
View content pane setting
Contextual filters
(Group node from OG membership) Content: Nid
Relationships
OG membership: OG membership from Node
(OG membership from node) OG membership: Group Node from OG membership
Argument input
Content: Nid source = From context
Required context = Node - Content ID
===========================
Panes Node template setting
Selection rule = OG: Node is an OG group content
Comment #54
DruDoc commented@spacereactor
In panel relationships add "Node from Node (on Node: Group membership [og_group_ref])" and select this relationship for providing the context.
You only need these in your pane views:
Contextual filters
(OG membership from node) OG membership: Group ID
Relationships
OG membership: OG membership from Node
and Argument input: from context - node: Content ID
Comment #55
spacereactor commentedThank DruDoc I manage to display other group post but it also display the current node content in the group content display twice.
I try to add another Contextual filters to exclude the current node but it doesn't work
Comment #56
DruDoc commentedIn the pane view, did you filter by content type (
Filter criteria
Content: Published (Yes)
Content: Type (= Your Group content(s))
Comment #58
boby_ui commentedHi,
I have the same problem here I am trying to show all the content list and showing the group id/ group name the contents are associated too, I have been trying for hours and finally it is showing I am using the Group membership: Node group membership relationships and I managed to show the (group membership) OG membership: Group gid field. I am using 7.x-1.3 version.
one bug or problem I am facing, if in the content type for that field I enabled the entity translation :
Field translation:
This field is shared among the entity translations. Enable translation
suddenly all the gid's disappeared when I do the new creations/update the content.. but when I disable the translation fields in the content type for that field, when I do the content update it is back again.
I can not get this to work? can someone please lead the way. I am trying to achieve showing list of node filter by content type and by groups they are associated and when user change language it will show the translated content in the correct groups.
I am attaching the screenshot of my config.
thank you
Comment #59
boby_ui commentedHi,
I have the same problem here I am trying to show all the content list and showing the group id/ group name the contents are associated too, I have been trying for hours and finally it is showing I am using the Group membership: Node group membership relationships and I managed to show the (group membership) OG membership: Group gid field. I am using 7.x-1.3 version.
one bug or problem I am facing, if in the content type for that field I enabled the entity translation :
Field translation:
This field is shared among the entity translations. Enable translation
suddenly all the gid's disappeared when I do the new creations/update the content.. but when I disable the translation fields in the content type for that field, when I do the content update it is back again.
I can not get this to work? can someone please lead the way. I am trying to achieve showing list of node filter by content type and by groups they are associated and when user change language it will show the translated content in the correct groups.
I am attaching the screenshot of my config.
Comment #60
DruDoc commented@boby
there is no contextual filter selected in your views.
Comment #61
boby_ui commentedHi DruDoc,
I need to list them without using contextual filter? can I do that?
thank you
Comment #62
DruDoc commentedOf course you can do that, but it means that your issue is probably not related to the original issue posted here. May be you should start a new issue. I do not have any idea about 'entity translation'. Could this be an issue with that module?
Comment #63
boby_ui commentedlet me recreate the new issues, I don't really understand is it related or not, what I can check is, if it is translated using the field translation, then the results will have ['und'] for the language, and if it is translated, then it will have ['en'], and then the views will stop working. it will not pull any results of the group id anymore.
Comment #64
codemuncher commentedThese settings finally worked for me:
Contextual filters:
OG membership: OG group gid
Relationships:
OG membership: OG membership from Node
(OG membership from node) OG membership: Node from OG membership
It's important to realize that you first need to add "OG membership from Node" first otherwise "Node from OG membership" will not be there and you won't have the ability to establish a relation with the fields (or content) of the nodes you're trying to show.
Comment #65
kristen polWhy is this so complicated??? argh...
Ok, I tried #64 but it doesn't work for me... I've pasted what I have used:
Contextual filters:
(OG membership from node) OG membership: Group ID
Relationships:
OG membership: OG membership from Content
(OG membership from node) OG membership: Content from OG membership
Help? I'll send a free Drupal 7 Multilingual Sites book to whoever points out the error of my ways :)
Comment #66
kristen polI got the group's posted content to show up via:
Relationships:
OG membership: OG membership from Content
(OG membership from content) OG membership: Group Content from OG membership
which isn't what I want but at least I got something! :P
What I want is the main group node. I'll keep trying stuff.
Update1
I did eventually get the same results as above using:
Relationships:
OG membership: OG membership from Content
(OG membership from content) OG membership: Content from OG membership
using a fresh view (rather than a cloned OG view).
I don't know why "Group Content from OG membership" and "Content from OG membership" are both there if they yield equivalent results.
Update2
Now I'm getting the same results with just:
Relationships:
OG membership: OG membership from Content
and no other relationships... ??? I'm so confused o_O
Update3
Maybe someone could post some views code for some of these scenarios?
Update4
I've made progress... I hadn't chosen the relationship for my title, e.g.
(Group node from OG membership) Content: Title
so there is hope now! I see the light at the end of the tunnel... sounds like a good blog post.
Comment #67
kristen polProblem
Want to show some information in a view that comes from the main group node.
Solution
Content: Title)OG membership: OG membership from ContentOG membership: Group Content from OG membershipand choose to use the previous relationshipOG membership from nodeOG membership: Group IDwhich will default to using the relationshipOG membership from nodeContent: Titlefield and choose theGroup node from OG membershiprelationshipSettingsunderQuery settingsand chooseDistinctandPure distinctSo... I'm wondering now if this is really the best way to do this? It seems rather complex.
Comment #68
liquidcms commentedyes, i agree completely... lots of people i think are having issues with this because the chain required to set this up is far more complex than it needs to be.
Comment #69
codemuncher commentedYa it's complicated but, trying to do the query yourself will lead to things that will break at some point. Views helps you with avoid these problems. The better way would be to create a specialized field, like the fields Organic Group comes with. But that could take longer.
Comment #70
Kirschbaum commentedKristen Pol's overview of the solution seems like exactly what I need. Unfortunately, it looks like OG/Views has changed the names of some of the relationships and contextual filters in the last couple months. Is anyone able to get this working with the most recent release of OG/Views?
Comment #71
cangeceiro commentedIve been struggling with this for a few hours now, I have a table view that lists content, and i want to add a column that shows what OG it is associated with. None of the suggestions listed here seem to have worked. Closest I have got is the suggestion in #67, but the second title field shows the title of the node and not the OG node like one would expect. And the title field is using the relationship.
Comment #72
colin_young commentedI was able to get my related group following the steps in #67, but I was still getting duplicates. Finally figured out that it was the sorting by post date that was not using a relationship and therefore returning 1 row for each group content item. Adding the relationship there fixed it up for me.
Thanks to all in this thread for all the details and work in getting this scenario working.
Colin
Comment #73
d0t15t commenteddoes the method from #67 work for og7.x-1?
the relationship from step 4: OG membership: Group Content from OG membership seems to be missing...
Comment #74
MauPalantir commentedWell, it seems that currently there is an odd behavior in og.views.inc @ line 67 (in views_data_alter()):
And then come all the OG membership relations for that entity type, including the ones that define Group @entity from OG Membership.
As far as I can see, og_get_all_group_content_entity() returns with only the entity types that can be a group content,
so if, for example, you have some group node types but no node types that can be a group content, then Node entities will not appear in Views
as possible group entities.
In my use case, I had a custom entity type (Record) that were organized with group Nodes, but there were no node types can could be group content, so no OG viws relationships were generated for node entities, even though I had properly functioning group nodes.
I temporarily disabled this check, and thus I have all entity types as possible groups (but this got me some nonsense like
a relationship of possible Group Files, so I guess the proper solution would be that the function checked for whether the entity type
can be a group content OR a group, and add available relations accordingly)
Comment #75
seaneffel commentedI have the answer to the original post.
It takes three cascading relationships to display a node and its related group in one row of a view:
1. Add relationship "OG membership: OG membership from Node"
2. Add relationship "OG membership: OG group gid" and set it to depend on the prior relationship (see #1).
3. Add relationship "OG group: Node from OG group" and set it to depend on the prior relationship (see #2).
Then I add the "Content: Title" field and set this field dependent on the last relationship (see #3). Seeing that that works you can add a filter using the same relationship. I can't speak to the issue of distinct rows, I have not tested that.
The module works fine and doesn't require any patches. But it does beg for some simplicity, or at least a clear answer to help someone when they run into this trouble. Marking this issue as fixed.
Comment #76
seaneffel commentedOr, well, works as designed.
Comment #77
nikkilabrum commented@seaneffel thank you so much for you simple explanation! It really helped me out :)
Comment #78
jrbeemanThis appears to have changed since February's post by seaneffel. To do this in latest OG as of this writing (7.x-2.3), you need the following relationships:
1. OG membership: OG membership from Node
2. (OG membership from node) OG membership: Group Node from OG membership
So, the 2nd relationship depends on the first. Once these relationships are setup, you can add fields or filters to your view based on the 2nd relationship (e.g. show the group title).
Comment #79
legovaerI managed to get this done with only one relationship.
https://drupal.org/node/1942282
Comment #80
seaneffel commentedNumbers 75 and 79 provide different results to solve different use cases.
#79 gets a gid based on the currently loaded node. This is good for showing nodes from a group on the current group page.
#75 gets a gid of any node regardless of the currently loaded node. This is good for showing nodes and their parent groups on, say, a user profile or a dashboard page.
Comment #81
dafederCan someone explain why og_group_ref doesn't work like any other entity reference field? Looking at how the entities and database tables are structured it seems like there's no need to join the {og_membership} table; the relationship is right there directly in {field_data_og_group_ref}. If there's something about the OG data model that makes this impossible that I'm not getting, wierd, but ok, but otherwise is this just a question of a bug in the code that can be patched?
Comment #82
gettysburger commentedI am trying to use #75 to create a view of group content with a field that shows the group name, outside of a group context. The problem I am having is with "2. Add relationship "OG membership: OG group gid" and set it to depend on the prior relationship (see #1)." I have no "OG Group gid" in my list of available relationships. Any thoughts? Thanks.
Update: actually I got it working through a relationship through the node author. Go figure. I will check back when I figure out how that worked...
Comment #83
mazzy27 commentedHow does this work in 7.x-2.7?
Comment #84
garchris commentedHas anyone been able to get this to work in 7.x-2.7?
I am able to display related content on the group page, but I am unable to get all content associated with this page, eg members' blog posts, to show at pages/%group/blog.
I am able to get all blogs that are group content, but as soon as I add contextual filter, I get "There is no content in this group". I have tried many of the solutions in this post but none seems to work for 7.x-2.7 version.
I've:
I have spent several hours trying to get this to work. Any help is greatly appreciated.
Comment #85
pbcelery commentedThese aren't working for me.
It's frustrating not being able to show related pages when on a group-content page. E.g. I'm on a group, view a subpage, want to see other subpages. Can someone post a view export? I'll recommend OR Extras add this as a canned view.
Comment #86
diddism commentedFor 2.7.
The panel needs the relationship. This can be added on the contexts-page of the panel. The relation I added was: Node from Node (on Node: Groups audience [og_group_ref])
When this is added it can be chosen instead of "This node" when Views panes are added to a page-layout.
This works with the default OG Content-view with the relation OG membership: Group Node from OG membership added to it. (on groups without content this gives No content in this group however.)
Comment #87
slcmayor commentedI've found another way to achieve this. Install Corresponding Entity Reference (CER), create an ER field on the parent content type, create a CER preset where the child ER field is left and the parent ER field is right, do a CER bulk update of nodes, and you'll be able to see your child nodes in a view with the Content: Title field and a relationship to 'Content entity referenced from _child ER field_'. Hope this helps!
Comment #89
joelpittetDrupal 7 reached end-of-life and the D7 version of Organic Groups is no longer being developed. To keep the issue queue focused on supported versions, we’re closing older D7 issues. If you still have questions about using Organic Groups on Drupal 7, feel free to ask. While we won’t fix D7 bugs anymore, we’re happy to offer guidance to help you move forward. You can do so by opening (or reopening) a D7 issue, or by reaching out in the #og channel on Drupal Slack.
If this issue is still relevant for Drupal 10+, please open a follow-up issue or merge request with proposed changes. Contributions are always welcome! 💙