Hi,

I have defined a custom node type. It has extra fields, and the content from those is saved in my customtype_node table. My question is, if I programmatically create a node using node_save, will the fields be inserted into the right table automatically? Or do I need to call node_save and then drupal_write_record for the customtype_node table?

Thanks,
Benjy

Comments

jaypan’s picture

If you add the type to the node object before passing the object to node_save(), it will call hook_insert() for that content type. So as long as you properly attach the data to the node object before calling node_save(), it will correctly save all the data to the correct spots in the database.

One point though - you should always call node_submit() on the node object before you call node_save(). This allows other modules (such as access modules) to make necessary changes.

Contact me to contract me for D7 -> D10/11 migrations.

benjymessner’s picture

Thanks very much for replying. Just to clarify - does this mean that my module must implement the hook_nodeapi() hook?

Thanks.

jaypan’s picture

Yes and no. You don't need to use hook_nodeapi() for the process you have described, but if you have defined a custom node type, then you should be implementing hook_nodeapi() and using the $op of 'delete_revision' to delete the relevant rows from your tables when a revision is deleted (i.e. - all the rows with the vid of the node being deleted, not the nid). But again, for the situation you were initially asking about you don't need to implement hook_nodeapi().

Contact me to contract me for D7 -> D10/11 migrations.