The api call to the index method i.e. http://domain/?q=endpoint/node returns an index of nodes (this call can be paged too. e.g. http://domain/?q=endpoint/node.json&page=2&pagesize=10 ).
It does not return the node body with it.
node body is in a separate table (field_data_body) table
I needed the index to contain the body too, which I can parse and display as a feed on my application.
I was looking at "services views" module but could not it to work.
So I hacked around and played around with the node_resource's index method to respond back with the join of the two tables and thus containing the node body for a given node id.
Code snippet:
It does not return the node body with it.
node body is in a separate table (field_data_body) table
I needed the index to contain the body too, which I can parse and display as a feed on my application.
I was looking at "services views" module but could not it to work.
So I hacked around and played around with the node_resource's index method to respond back with the join of the two tables and thus containing the node body for a given node id.
Code snippet:
function _node_resource_index($page, $fields, $parameters, $page_size) {
module_load_include('inc', 'services', 'services.module');
$start = (($page)-1)*$page_size;
$query = db_select('node', 'n');
$query->join('field_data_body', 'u', 'n.nid = u.entity_id'); //JOIN node with field_data_body to get node body
$query->fields('n',array('title','created'))//SELECT the fields from node
->fields('u',array('body_value'))//SELECT the fields from field_data_body
->orderBy('created', 'DESC')//ORDER BY created
->range($start,$page_size);//LIMIT records if (!user_access('administer nodes')) {
}
$result = services_resource_execute_index_query($query);
return services_resource_build_index_list($result, 'node', 'nid');
}
Comments
Post a Comment