我从视图中提取并使用此查询。
(它意味着传递一个节点id,并返回所有具有此节点id的节点作为节点引用)
function jsonview_node_update($node){
if ($node->type == "company") {
$query = "SELECT DISTINCT node.title AS node_title, node.nid AS nid
FROM {node} node
LEFT JOIN field_data_field_campaigncompany ON node.nid = field_data_field_campaigncompany.entity_id AND (field_data_field_campaigncompany.entity_type = node AND field_data_field_campaigncompany.deleted = 0)
WHERE (( (node.status = '1') AND (field_data_field_campaigncompany.field_campaigncompany_nid IN ('".$node->nid."')) AND (node.type IN ('campaign')) ))";
$result = db_query($query);
file_put_contents('/tmp/ref.txt',json_encode($result));
}
正在返回
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node' in 'on clause': SELECT DISTINCT node.title AS node_title, node.nid AS nid FROM {node} node LEFT JOIN field_data_field_campaigncompany ON node.nid = field_data_field_campaigncompany.entity_id AND (field_data_field_campaigncompany.entity_type = node AND field_data_field_campaigncompany.deleted = 0) WHERE (( (node.status = '1') AND (field_data_field_campaigncompany.field_campaigncompany_nid IN ('14')) AND (node.type IN ('campaign')) )); Array ( ) in jsonview_node_update() (line 224 of /jsonview.module).
不确定这里有什么问题..我已尝试过关系和其他几个模块而且没有人真正做到这一点
答案 0 :(得分:0)
(在问题编辑中回答。转换为社区维基回答。请参阅Question with no answers, but issue solved in the comments (or extended in chat))
OP写道:解决:
function jsonview_node_update($node){
if ($node->type == "company") {
$query = "SELECT DISTINCT title, nid
FROM {node} node
LEFT JOIN field_data_field_campaigncompany ON node.nid = field_data_field_campaigncompany.entity_id AND (field_data_field_campaigncompany.entity_type = 'node' AND field_data_field_campaigncompany.deleted = 0)
WHERE (( (node.status = '1') AND (field_data_field_campaigncompany.field_campaigncompany_nid IN ('".$node->nid."')) AND (node.type IN ('campaign')) ))";
// $query = "SELECT nid, title FROM {node}";
$result = db_query($query);
// $result = db_query("SELECT nid, title FROM {node}");
foreach ($result as $record) {
file_put_contents('/tmp/ref.txt',json_encode($record),FILE_APPEND);
// Do something with each $record
}
}
}