I'm currently using the following custom content types on my site: Account, Contact, and Location. The account type is the "parent object" and the location and contact types are the "child objects" of the account.
This relationship is setup in the following manner:
- Both the location and contact types have an entity reference field that points to an account type.
- Each account contains views (EVA Module) of referencing content (one for contacts and one for locations)
- Everything is streamlined by using the Entity Prepopulate module
While everything for the most part is working perfectly, I've run into problems when trying to use views.
As of now, I have a view that displays nodes in a table while restricting the content type to accounts. I'd like to display fields from the related location and contact types in this table; furthermore, I'd like to setup exposed filters to show only accounts that have a certain contact or location associated with them.
Seeing how the location and contact types point to the account and not the other way around, I can't seem to figure out how to do this. I believe this was solved in Drupal 6 using back references, however, I can't seem to find a current solution for Drupal 7.
Any and all help is appreciated.
Comments
When you set up your
When you set up your relationship within views, there should be an option with a syntax something like "referencing entity," which should allow you to point backwards through the relationship at the thing doing the referencing.
Thank you for responding to
Thank you for responding to my post. I found the relationship you mentioned in views
I'm still having trouble using it though. When I configure a new field to display a content using this relationship, the view prints duplicate account fields-- each with its own contact/location information. Is there a way to group these into one display field?
The other problem I'm having is that both my location and contact types are using the same entity reference to accounts (ie: I used the option to use an existing CCK field when creating them); thus creating separate filters to filter by contact and location is proving to be difficult.
Any suggestions?
Problem One
After playing around with this for the past few hours, I'd like to clarify the issues a little better. As of now, I'm running into to two different problems. I'll describe the first one in this post.
As a quick recap, my setup has both contact and location types that reference an account type. I currently have a view that displays accounts, but I'd like to add related contact and location information as well. Here's example of what I'd like display in each row
I can't set this up due to the fact that the account type does not have a direct relationship to the contact and location types. After following misoks' suggestion, I was able to add those fields; however, I'm having a duplication issue. Here's a simple example of what I'm seeing just by adding the contact information to the view
I then tried grouping the results by account, which then looks like this:
Account 1
Account 2
While this is a lot closer to what I want, I'd rather have each section collapsed into one row where the contact information is in one field and is comma separated (or line separated, etc.). Is this possible?
Problem Two
Both my contact and location types are using the same entity reference field to reference the account type. In other words, instead of choosing add new field, I chose add existing field when setting up the second contact type which has lead to an interesting problem.
Currently, I setup a view of accounts (as described in the prior post), and I added an exposed filter to allow users to filter accounts by the Referencing entity which should be a contact or location; however, there's no way to specify one or the other. In other words, imagine a view of accounts with one exposed filter for contacts and locations instead of having an exposed filter for contacts and a separate exposed filter for locations.
I know I can fix this by going by editing the content types so they don't share the same field; however, I'd like to know what the best practices are for when and when not to use a new field or an existing field. Should I just edit the content type or is there a better way to accomplish this task while leaving the fields the way they are?
Please disregard the last
Please disregard the last reply (Problem 2). After playing around with it for more time, the only reason I can see to use an existing field for several contact types is if you plan on being able to search both types of content with one field-- obviously something I'm not trying to achieve. I've since gone back and updated my content types.
With that being said, does anyone know how to fix this grouping issue? I can't stand how I have 20 rows of the same exact data with the exception of one or two fields. There has to be a way to collapse them into one row...
Close
After spending quite some time on this, I don't believe the grouping feature I'm looking for is an issue with Drupal-- it appears to be a limitation of SQL.