CCK - Creating a node type that links/relates to other nodes (content)
So i have this idea that i want to create using drupal.
After a couple of months playing around with drupal and installing various modules one of the modules stood out, CCK. Having the ability to created custom node types seems invaluable so i started to do as much work using CCK as possible. What im looking to create is a bunch of custom node type that "relate" to each other. I will give you a simple example.
-------------------------------------------------------------
Node type 1: Product
Fields:
Product Code
Product Name
Product Description
Product Price
-------------------------------------------------------------
Node type 2: Orders
Fields:
Order Number
Product Code <- (The interesting part)
Order Date
-------------------------------------------------------------
Creating the node types is pretty simple but i want some special functionality out of my "Orders" node type. Instead of just entering the product code from the users memory (the user trying to remember "what product code is a packet of cheese and onion crisps?") i want either and field that will auto-complete or even better a pull-down menu that references all the product codes that have already been entered into drupal via the Product node type. If you are the sort of person that creates database schema's then i hope you will understand what i am aiming for as i want a "link" to the product to the orders the same way you link two relational tables in a database via a "foreign key". The main reason for this is i intend to use third party software to later link to my drupal database and relate / link all the data for other uses. This is of course only a simple example of what i need to do and the end result will have many more other node types linking to the one node (orders).
Its also worth mentioning that im not actually building a system for products and orders. its just an example.
So..... is there a cck Module that allows me to create these dynamic pull-down menus generated from other content? Do i have to create my own mudule to handle this task or can it actually be accomplished using the CCK?
I hope this post made sense but if it didn't. please don't hesitate to ask for further info! =)
Regards, Harris

Hello, This is really a good
Hello,
This is really a good question, because I also was strugling with the similar problem.
First of all, what type are you using for Product Code field? You should use Node Reference but not Number or Text. Node Reference is a CCK field module which is bundled in CCK package (as I remeber). They have a dropdown list or AJAX autocompletion field for choosing a node of a specified type.
CCK is a greate module and it creates database tables for your content types automatically. As I know, it will NOT create a foreign key constraint for Node Reference field in MySQL. You will need to create it yourself.
BUT! It should create it if you run it against PostgreSQL database.
----------------
Regards,
Dmitry Kresin, ARDAS group (www.ardas.dp.ua)
Cheers for the reply
Hi Duke,
The product code field is just an example that i guess someone would use if they were filling in an order so i assume the field type would just be a string. In the long run i want to be able to use CCK to create a relational database schema based on creating custom nodes that allow you to enter data into one node and then use that data in another node to create the database structure. The project im looking at to build is based on vessels and i wish to enter all the vessel characteristics. Now because vessels can have alot of equipment on borad that is common i dont want to have to manually type the name of that equipment. i want to enter the name and characteristics of the equipment prior to entering the characteristics of the vessel and then just "link" to the equipment. this of course is just a start. I then want to create a node type that i can enter where and what the vessel is doing. so i would like to enter the where and what of the vessel into a custom node but then link to the vessel which in turn links to the vessel equipment and so on. As you can imagine this could start to get rather big with many many relations. Thats the plan. But the important part is the linking of the data outside of drupal. primary keys and foreign keys would be perfect but if you have to ebter these keys manually it kind of defeats the point of have a user-proof application. does this make any sense?
Regards, Harris
I see... So, Node Reference
I see... So, Node Reference field is exactly what you need. You need to use it instead of Text if you want to have a reference to another node.
CCK doesn't create foreign key constraints for MySQL because InnoDB table type is required for them to work. All Drupal tables are created in default MyISAM type which doesn't support FK constraints at all. You should either create a patch for all your tables to use InnoDB type or consider to move everything to PostgreSQL.
----------------
Regards,
Dmitry Kresin, ARDAS group (www.ardas.dp.ua)
Please advice
Hi ARDAS & all,
I have a question regarding the scenario above, what if the product code is not found in the entry (as in the code has yet to be entered previously), is there a way/module that we can add a new product code in the Order node type?
Currently, I'm stuck at this if there's an easy/direct way user can add a new product code from the Order node type. I'm also using node reference for my case. But, as you all see that node reference is only able to do an existing referencing to an already created node, not for nodes that yet to be created.
Hope to hear some feedbacks.
Cheers,
- yeeloon
I haven't heared about such
I haven't heared about such module.
I'm afraid that current CCK implementation will not help you. You would better create a separate page 'node/NID/some-name-here' where you provide a form with a node add form embedded (subform_element) and a submit button. On submit hook you will save the newly added node and bind it to the existing parent node ... or something like that.
----------------
Regards,
Dmitry Kresin, ARDAS group - Web site development, Drupal services, Software development, IT outsourcing.
CCK comes with nodereference
CCK comes with nodereference which probably does what you need
--
I work for Ontwerpwerk
note about node references and foreign keys
The node reference modules works well for this, and you can use
"Advanced - Nodes that can be referenced (View)"
to define which foreign keys/nodes can be listed in the dropdown
hope this helps!
mac clemmens
nodes that can be referenced ??
Can u give us an example how we can do that. Step by Step prefered because i'm new to drupal.
Thanks !
Hi there, I want to reference a node too
Hello there, I am trying to reference a node's image, all i want is to only get the thumbnail as a link not the title.
At the moment i am developing a site with ubercart, where i have different products. On the product page i want to have a description, price and other atrributes as well as some related or same products as thumbnails linking to the original node. By using "similar by term" module, i am able to establish a connection between two terms of a vocabulary (which in my case is cataloge). After adding another field (which is called matching products) to my product content type, and enabling it for multiselect so it can hold multiple related products, i can only reference the title or the full node. Is there a way to reference the thumbnail of a related product....
my way
when you add a node refernce to a content type drupal creates a Db table like this
content_type_story
-------------------------------
nid | vid | node_reference_nid
ok I tryed to develop this function that from the nid of the current node gets the nodes that reference it, but I was not able to make it works (my first drupal function), this function is to print the teaser of the referencing nodes (nodes who have the reference_CKK field that points to the current node)
function get_referencing_nodes ($nid) {
$result = db_query(db_rewrite_sql("SELECT node_reference_nid AS rnid FROM {content_type_story} WHERE nid = %d "), $nid) ;
while ($anode = db_fetch_object($result)) {
$node = node_load($anode->rnid) ;
return theme_node($node, $teaser = TRUE, $page = FALSE) ;
}
}
but as I said this don't work I'mot still able to pass nid to the function in .... but hope this can help you
Bumping... Looking for this
Bumping... Looking for this one. Does not work in Drupal 6, there is different structure used in cck. I do not even know where in the table to find those fields.