DrupalORM provides a programmatic ORM interface to nodes and their corresponding CCK fields.
Assume you have a content type called "page" with the following node and CCK fields...
- Node title
- Node body
- CCK Field "field_desc"
- CCK Node reference "field_ref" which points to content type "story"
You could query "page" content type in the following ways...
orm('Page')->find(array(
'Page.nid' => 34
));
$nodes = orm('Page')->find(array(
'Page.field_desc' => 'foobar',
'Page.title' => 'hello world'
));
// $nodes will be an OrmNodeCollection object
print $nodes->{0}->title;
print $nodes->{1}->title;
// Or you can also do
foreach ($nodes as $node) {
print $node->title;
}
Assuming the corresponding nodes exist, both of these will return an OrmNodeCollection object which contains a set of PageNode objects. Also, any story nodereferences will be populated recursively....
<?php
$nodes = orm('Page')->find(array(
'Page.title' => 'bup'
));
// Prints title of corresponding Story node which is defined via CCK nodereference.
print $nodes->{0}->FieldRef->{0}->title;
// You can also do this
$nodes->{0}->FieldRef->{0}->body = 'Hello World';
// Now save the changes. There are many ways to do it...
// Method 1
$nodes->saveAll();
// Method 2
$nodes->{0}->save();
// Method 3