The ad_image module adds (or tries to add) an association from {ad_image} to {files}.
Obviously this may not work when creating a new node, because the node is created FIRST, and then files are stored on the database.
This has nothing to do with module priority, it has to do with the sequence of the insert procedure.
In fact, if you look at the {files} table you will notice a nid column, which contains a "back" reference to the newly created node.
There is no need to add a reference in the opposite direction (you can fetch the first listed file via SQL for a consistent behavior).
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | ad_module-264612-validation_and_file_association.patch | 9.39 KB | acolonna |
| #1 | ad_image.zip | 4.86 KB | acolonna |
Comments
Comment #1
acolonna commentedHere you go, I have made some quick changes (check the diff) just to it.
The DB schema should be also changed to drop the FID column.
This is just a rough fix done before leaving the office, but it should the direction to take:
1) during INSERT, FID is completely out of the business (association is deal with by the core modules);
2) during VIEW (read), the FID association is built backwards (from the file - and file_revision -, back to the node - and node_revision, and to the ad in the end);
You will see that I've put some validation in the right place.
Cheers
Comment #2
jeremy commentedPlease attach patches, not whole files, otherwise there's nothing to review.
Comment #3
acolonna commentedOk, I tried to create a patch (never had to do this before, I'm trying to help this community go forward for once).
The code is pretty self explanatory.
Comment #4
jeremy commentedThanks for creating a patch, that's very helpful for seeing what you're doing.
Regarding the patch, please don't make unnecessary formatting changes. In particular, you've changed the db_query to something that does not match core coding standards.
Also, your patch adds debug statements that shouldn't be there.
Otherwise, it looks like you're very much headed in the right direction. I'll do some testing with this soon. Thanks!
Comment #5
jeremy commentedFinally reviewing this patch closely, I'm finding it to be pretty unusable. It doesn't solve the core problem: an image upload can fail. All you've done is to add additional queries each time we display an advertisement, removing the optimization where we keep a copy of the active fid. If you want to revisit this patch and clean it up greatly, you can re-open it. But for now I believe it's fixing a non-problem.