欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Drupal node reference

shiping1 的头像

I am using two content types - test_parent & test_child In test_child there are two fields, both of type datetime And in test_parent there are two fields, week_no & 7 node references

I am using node_save to save a new node. After saving a node of parent type, and then saving the node of child type, i want to update the node it into the parent type.

I have completed creation of both nodes from code, and also i am able to update nid in parent type from code.

The problem is, the change in db is getting reflected in db but not on drupal node view. Even if i edit the node from drupal, it's showing -none- selected in node reference.

Please help.

shareimprove this question

closed as off topic by Kev Sep 13 '12 at 23:33

Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

 
   
More details needed. Is the change not reflected within the same page cycle only or also after a reload? Could you edit your question to show the code you use to update the parent? –  Henrik Opel Mar 30 '10 at 23:02
   
yes on page reload even. –  Nikunj Kotecha Apr 1 '10 at 14:03
1 
By the way, thanx Henrik, got it solved. After updating a node from code, i cleared the cache related to that node. I checked the node edit code in core module, and got the answer from them. Thanx anyways. – Nikunj Kotecha Apr 1 '10 at 14:04
   
You should post that as answer and then accept it. That way people looking at the same problem will find the actual solution. –  berkes Dec 15 '11 at 15:20

Two modules that can help with this kind of thing...

http://drupal.org/project/cnr

http://drupal.org/project/noderelationships

I was going to suggest to be careful you're creating the nodes and applying the relationships through the proper Drupal API channels, but it sound like it was a node caching issue.

shareimprove this answer
 
   
Thanx josh, sounds really good. –  Nikunj Kotecha May 23 '10 at 14:10

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



来自  http://stackoverflow.com/questions/2546795/drupal-node-reference


Corresponding node references

New development is done in the http://drupal.org/project/cer module. This expands the corresponding node reference functionality to enitities. Please focus all attention on getting a stable release of cer as soon as possible.

Cnr is looking for a comaintainer to resolve the remaining bugs. No new features will be handled.

Screenshots

Description

It syncs the node reference between two node types which have a nodereference to each other, so double editing nodes is no more needed. If one node has a reference the other node receives also a reference to the saved node if it is referenced in that node.

Updates

Release 6.x-4.0 doesnt require setting the options to unlimited, all is handled by cck now. The old setting to allow setting to single is no longer present since it is obsolete. To upgrade, run update.php and manualy set the allowed references on each nodereference instance. The older branches are not supported anymore so you should upgrade.

Dependencies

6.x : CCK
Node reference (comes with cck)
7.x: Node reference (included in References)

Example

Node type A has a node reference to node type B and node type B has a node reference to node type A. When you create node X of type A and reference it to node Y of type B Node Y will also receive an update in its node reference field pointing to node X.

Install

- To install enable the module at admin/build/modules
- Create node type A
- Create node type B
- Create a node reference field on node type A pointing to node B
- Create a node reference field on node type B pointing to node A
- Go to the settings page at admin/settings/corresponding_node_references. Select to enable the corresponding referencing for these node types pointing to each other.
- Create some nodes and reference them to each other

Get involved

  • Write a review for this module on drupal modules
  • Help write or improve the documentation.
  • Help translate this module at http://localize.drupal.org/translate/projects/cnr
  • Report any bugs, feature requests, etc. in the issue tracker.
  • Contact the maintainer with any comments, questions, or a quote for custom module customizations.

How can you be kept up to date?

This module is partialy sponsored by One-agency.be

Dominique De Cooman can be contacted for paid customizations of this module and for Drupal consulting and development. This is how I think about development and about consultancy

Project Information

Downloads


来自  https://www.drupal.org/project/cnr



Node Relationships

Example of the ERD provided by the Node Relationships module

The Node Relationships module provides methods to complete two way relationships between content types enhancing the features of node reference fields.

Almost all the settings to administer the features of this module can be located at Administer -> Content management -> Content types -> [type] -> Relationships.

Features:

The Node Relationships module provides the following features:

  • Node reference extras:

    This module provides several enhancements for node reference fields configured to use the autocomplete widget:

    • View reference in new window
    • Edit reference (in modal frame, updates widget if node title changes)
    • Search and reference (single and multiple value selection)
    • Create and reference
    • Translate and reference

    When these options are enabled, a new button for each one will be rendered in the node edit form, next to the corresponding autocomplete widget of the node reference field. These buttons will open a popup dialog where each feature is available.

    For nodereference fields defined with multiple values, a new button will be available next to the "Add more items" button that can be used to search and reference several nodes at a time.

    The "Search and reference" feature uses a view that is dynamically configured so that a single view can be reused by several node reference fields. A default view is provided with basic fields and pages for table or grid styles. You can modify and/or clone (recommended) this default view to add more field, filters, etc. A filter per node type is dynamically created to match the "Content types that can be referenced" option in the global settings section of the node reference field. Note that you should configure this option explicitly even if you use a view for the node reference field.

    The "Translate and reference" feature is available when the Drupal core translation module is enabled, and additional support is provided when the Internationalizationmodule is enabled. It is recommended to enable the "Switch interface for translating" option in the Multilingual system settings page for the "Translate and reference" feature to work properly. When the "Translate and reference" option is enabled for a particular node reference field, references that already have translations will be automatically assigned to the values of node reference fields when a node translation is started. For those that do not have translations, a message will be displayed on the create translation form to warn the user a translation is missing and an option to translate and reference will be provided.

  • Automatic back references:

    This module provides a method to display back reference views on referred nodes. Back reference definitions are taken from the "Content types that can be referenced" option in the global settings section of node reference fields. Note that you should configure this option explicitly even if you use a view for the node reference field.

    These back references do not need additional data stored in the database. Instead, views with the proper relationships are used to join the node reference field data with the corresponding nodes in the database. These views can then be used from the referred content types to provide a list of referrer nodes. The Node Relationships module provides a default view that you can modify and/or clone (recommended) should you need to add more fields, filters or change any other option to suit your needs.

    Each back reference can be displayed using one of several methods to render the corresponding view in the referred node itself (Field, Page and Tab).

    • Field: When a back reference is configured as a "Field", the Node Relationships module creates a CCK field automatically that provides the view output, and you can drag'n'drop this view to any position from the "Manage fields" panel of the content type. Note that no input widget is provided for this kind of fields, only the view output is provided.

      Field formatters available:
      - Back references view: renders the customized view as usual.
      - Back references count: displays the count of back references (taking node revisions into account).

    • Page: This method provides a fieldset where all back reference fields assigned to this region will be rendered. This fieldset can be dragged to any position in the node using the "Manage fields" panel of the content type.
    • Tab: This method provides an alternative to the "Page" region, but the back references are displayed on a new tab "Relationships" added to the nodes where this option is enabled.

    A note on performance of back reference views: latest development snapshots of CCK include a feature that allows fields index their columns. This is implemented for node and user reference fields that automatically create an index by the reference value column (see: #231453: Allow indexing columns). This means back reference views can take advantage of this index to resolve the join with the field table used by the automatically customized relationship on these views. Still, it is recommended to perform an EXPLAIN on the queries executed by views as peformance may depend on a few more factors. You may also wish to take advantage of the new Cache options implemented in Views since 2.6 (see:#468824: Add caching system to Views).

  • Entity relations diagram:

    This is a basic diagram of the relations of current content type with others (referred from and refers to). It can be used to walk the relationships of all types in the system. This diagram is available per content type from Administer -> Content management -> Content types -> [type] -> Relationships.

Requirements:

Recommended:

  • Reverse Node Reference: Enhances Views with reverse relationships for Node Reference fields.
  • Content Type Selector: When you are on the "Relationships" tab of the content type administration pages, it helps navigate from one type to another easily.
  • You may also want to check out the modalframe_cck_manage_fields, part of the Modal Frame Contrib Package. It opens CCK field and group settings forms in modal frames.
  • Referential Integrity for CCK: allows you to decide what to do with reference values when a referenced entity (node or user) is deleted.
  • Panels: If you use Panels, then you may want to check out the CCK integration features, where you can plug any field in your node view based panels, and that means you can place your Back reference views at any position in your panels, as a block, and so on.
  • Checkall: provides "Check all / Uncheck all" feature to module administration pages.
  • Views Fluid Grid: provides a new Views style plugin that implements a fluid grid layout that is pretty nice for image galleries.

Advanced usage:

How can you get involved?

This module has been sponsored by Gamefilia.

Project Information

Downloads


来自  https://www.drupal.org/project/noderelationships



I have added related nodes using Node Reference module provided by the references module.
Now I want to retrieve all the related nodes. So I am looking for a function which takes a node id as input and returns all the related nodes.

Is there any function provided by Drupal API or reference module which helps me getting nodes related to a node?

I tried searching in the module functions but I found nothing.

shareimprove this question
 

I don't know of an API function specifically for that but it's fairly simple to implement one using existing API methods:

function get_related_nodes($master_nid, $field_name) {
  // Load the 'master' node
  $master_node = node_load($master_nid);

  // Get the node reference items attached to this node
  $items = field_get_items('node', $node, $field_name);

  // Loop through and grab the nids
  $nids = array();
  foreach ($items as $item) {
    $nids[] = $item['nid'];
  }

  // Return the fully loaded reference nodes
  return node_load_multiple($nids);
}
shareimprove this answer
 
   
Fist Many Thanks for the answer Clive..However if there were an inbuilt function it could have been cooler..This looks to be cool way..will implement it...Many Thanks....Smith – Smith Jun 21 '12 at 19:38 








 




 

 
普通分类: