joint icon indicating copy to clipboard operation
joint copied to clipboard

Breaks in embedded documents.

Open danielmorrison opened this issue 13 years ago • 4 comments

Noting this here (without a fix, sorry) mainly so others don't fall down the trap.

I was using Joint on an embedded doc (in another embedded doc) and it looked like it was saving, all the metadata was there, but I couldn't get the files out.

More info here: https://groups.google.com/forum/#!searchin/mongomapper/joint/mongomapper/CN4OAL4S-Jw/HDbFPfyjcasJ

danielmorrison avatar Jul 12 '11 03:07 danielmorrison

Funky, must be an issue since switching to active model. Use to work as I built a client app that uses it this way and had no issues.

jnunemaker avatar Jul 12 '11 12:07 jnunemaker

Related: destroy_nil_attachments() calls set(), which is not available on EmbeddedDocument.

jamieorc avatar Nov 22 '11 19:11 jamieorc

Wondering what you think of the following. Currently, when deleting an attachment, destroy_nil_attachments() is called after_save, necessitating calling set() to set the four keys to nil in the db. What do you think about this being broken up into two routines, one called before_save and one called after_save.

before_save would call a method to assign nil to the four convenience attributes.

after_save would still call destroy_nil_attachments(), minus the set command, because those attributes would have been assigned nil before save.

This would then work for EmbeddedDocuments.

Thoughts?

jamieorc avatar Nov 22 '11 19:11 jamieorc

I forked and updated code with fixes and tests for EmbeddedDocument use.

  • new class method "nullify_nil_attachments_attributes()" called before_save
  • class method "destroy_nil_attachments()" now only calls gid.delete(id) after_save
  • changed @nil_attachments from Set to Hash key is still name, value is the file id
  • these changes obviate the need for calling set() after_save, so works with EmbeddedDocument

I've released MM 0.8.6 and >= MM 0.9.x versions at

  • jamieorc-joint -v 0.5.6
  • jamieorc-joint -v 0.6.1

My fork has these tags as well as branches for each of these versions. I have not merged any changes into master.

jamieorc avatar Nov 23 '11 20:11 jamieorc