How is the file in the files table linked to the node table in the database. The files are the files that are attached to the nodes. I was trying to find out what node the file belongs to and found no relationship between the two tables. Does anyone know how they are linked?

Thank You.

Comments

dman’s picture

Home » Developing for Drupal » Module developer's guide » Reference » Tables: other (core)
nodes have versions (vid)
the file revisions table links files with specific node versions, so you have to join twice

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

mooffie’s picture

You're talking about D6.

Drupal itself doesn't really record any association between files and nodes.

In other words, modules that associate files with nodes have to provide their own table. That's what the core 'upload' module does.

(The page dman linked to is too old. The document explaining how to upgrade modules from 5.x to 6.x is a better one.)

dman’s picture

I think you are right. I was thinking about D6, talking about D5, and that link really is old - for D4 !
Oh sheesh. Those diagrams need to die then?
But I would say that upload.module is part of Drupal ;-)

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

GN’s picture

In D6, this info is recorded in two tables: "files" and "upload"
Fields:
files.fid, files.uid, files.filename, files.filepath
upload.fid, upload.nid, upload.vid, upload.description, upload.list, upload.weight

files.fid and upload.fid is the same File ID.

GN’s picture

...and upload.nid is the number of node which upload.fid file is attached to.

silkhost’s picture

thanks for your responses. I was only looking at the files and node table, I did not notice the uploads table at all.

Yes, the document is very outdated. I had to read the 4.x and 5.x documentation to get a feel for drupal 6.x.