0

Sorry if this is a repeated question, tried many suggested options but no result.

There is business model of 1 to N relationship "parent and children".

I am working on a project where i have a content type building as parent and apartment as child. within a building there could be N number of apartment and every apartment has it is own contents. something similar to attached screenshots

Parent :

enter image description here

Children :

enter image description here

-Building #1 --Apartment #1 --Apartment #1 --Apartment #1 --Apartment #1

I guess there are few modules which could help "Reference module, Entityreference, Views and Taxonomy"

0

The 'Description' tab seems to be the normal 'View' tab for the node. So you first need to change that tab's title to 'Description' only for the building type. Look here to do this: Change name of a tab for a specific content type

As to you two content types: You can create an entity reference field on the building content type that references apartments. Look at the Inline Entity Form to help you with content editing in this regard. Or you can do it the other way round by putting the entity reference field on the apartment that references the building (more manageable), especially if you are going to have lots of apartments.

Then as to the Apartments tab. You need to use entity reference module and views. You will create a view page of nodes filtered by type apartment. You add the relationship to the building, and then add a contextual filter of nid that includes that relationship. You set the path of the page as node/%/apartments, and add a menu tab with the title 'Apartments'. For a tutorial refer to Drupal 7 tutorial - How To Create Tabs With Views or Taming the Beast: Learn Views with NodeOne episode 21 and 22.

| improve this answer | |
0

To list all nodes of the parent, i.e. siblings.

// Node ID to to search by
$nid = 1;

// Load Node
$node = node_load($nid);

// Get Node's Content Type
$type = $node->type;

// Search for siblings
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->propertyCondition('type', $type)
  ->propertyCondition('status', TRUE); // Get only active nodes
$result = $query->execute();

// Load Sibling Nids
$nids = array();
if (isset($result['node'])) {
  foreach ($result['node'] as $node) {
    $nids[] = $node->nid;
  }
}

// Load Sibling Nodes
$nodes = node_load_multiple($nids);

Building relationships

In regards to structuring a 3 tier relationship, I personally use Entity API and simply reference Nodes to Terms. In cases where I need to create a relationship between Nodes only, I've used an Entity Reference module, or now, I just create a module, which attaches a field with an option to enter a referencing node.

You may also want to check out a Relation module, which has a more complex use to it.

| improve this answer | |

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.