3

How would I go about implementing the following content types + fields

  • Parent
    • Name
    • Description
    • Other fields (e.g. location, date)
    • Number of children
  • Child
    • Name
    • Description
    • Other fields (e.g. location, date)
    • Parents (entity reference)

Children can have multiple parents.

Basically what I want to do is to create a new Child and "tag" a Parent in it. A View with a list of Parents would then display something like "[Parent Name] has x Children" for each Parent.

I'm very new to Drupal so if I'm going about this completely the wrong way, please let me know!

5

This video series helped me an infinite amount: http://vimeo.com/33251051, http://vimeo.com/33252553.

  1. Make sure Child has an entity reference to Parent.
  2. Create a new view
  3. In Filter Criteria, add a new Type (= Parent)
  4. In Advanced>Other, set Aggregation to YES
  5. In Advanced>Relationships, add a new relationship for "A bridge to the Content entity that is referencing Content via field_parent" where field_parent is your entity reference. Call this "Parents"
  6. In Fields, add Content: Title and when prompted set its Aggregation type to Group results together
  7. In Fields, add Field: Parents and when prompted set its Aggregation type to COUNT (Distinct)
  8. Ta-da
  • Where is the relationship present? – sokratis Sep 2 '14 at 14:06
  • Far too late to comment on a question inside a comment, but it is in the advanced field and this entire answer made sense to me only after I changed the relationship from a Node Reference to an Entity Reference, just in case if it helps any future visitors – skv Apr 29 '17 at 7:42
0

You can use combination of Taxonomy and Content Types... Please follow below steps to complete the functionality....

  1. Create a vocabulary called parent.
  2. Add parent terms -- You can give term name & description.
  3. Create a Content Type Called Children
  4. Add Term Reference field and reference to Parent Vocabulary.
  5. For above field give number of values as Unlimited so that Children can have multiple parents.
  6. Use views module to create a new view with base table as taxonomy and show list of parent terms with number of nodes tagged using views aggregation functions.

It makes sense to create a content Type for parent also if you have many parents...

In views you can add a entity reference relationship and use aggregation setting and check you can able to pull off what you are trying to achieve i guess...

Optionally check this module if it solves the issue drupal.org/project/nodereference_count....

If nothing works you can use views php module and write a single query to achieve the functionality...

Hope it resolves your problem.

  • Hi, thanks for the response. The Parent really needs to be a Content Type I think as I need the ability to add other fields. I'm sorry my question didn't say this - I will update! – dav_i Sep 11 '12 at 13:04
  • You can add new fields to taxonomy also in Drupal 7... If you have lots of parents then obviously you need to implement as content type... If you have limited set of parents then i suggest taxonomy... – Anil Sagar Sep 11 '12 at 13:05
  • Parent counts will be about 50-100 to start with, Child counts will be about x10 Parent count. Is this starting to get into Content Type territory rather than Tax.? – dav_i Sep 11 '12 at 13:09
  • Yes, It makes sense to create a content Type for parent also... In views you can add a entity reference relationship and use aggregation setting you can able to pull off what you are trying to achieve i guess... Optionally check this module solves the issue drupal.org/project/nodereference_count If nothing works you can use views php module and write a single query to achieve the functionality... – Anil Sagar Sep 11 '12 at 13:11
  • I checked out Node Reference Count but it's Dev only so don't really want to use it in production. A quick Google and it seems like Aggregation could be what I need! As I said, I'm new to Drupal so even just the terminology is throwing me off. Thanks for pointing me in the (potentially) right direction. I will report back when I have had a play. – dav_i Sep 11 '12 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.