Friday, July 18, 2008

Drupal write query relate to revision control

When write sql in drupal that related to revision control, the best practice is ONLY use nid in the node table, for the rest of the tables, use vid instead. That will prevent contents from syn. See this example for reference:

$query ="SELECT DISTINCT n.nid FROM content_type_event e
INNER JOIN node n ON n.nid = e.nid
INNER JOIN content_field_feature cff ON cff.vid = n.vid
INNER JOIN content_field_date_and_time cfdt ON cfdt.vid = n.vid
WHERE n.status = '1' AND = '0'
AND cff.field_feature_value ='1'
ORDER BY cfdt.field_date_and_time_value ASC LIMIT 2";