anlek/mongify

Cancel insert from before_save

Closed this issue · 5 comments

It would be nice to be able to cancel insertion of the current record from within a before_save block. I've got an embedded table and I want to cancel the insert if the record is a dup.

There is a small chance that if you make row = nil it will not write anything for that record.

Actually you might have to set row = {}.

Thanks for the tip anlek, but I can't get it to work. Here is a gist, would you mind taking a look? https://gist.github.com/steveo7/9783034

Ok, in the next little bit I'll add a fix to this issue. I'll keep you updated.

Something I've noticed that may or may not be helpful. In the before_save of an embedded table, any docs of that type that have already been embedded, are read only in the parent_row. I have been able to work around this by editing or deleting the embedded doc from the parent_row inside the before_save of an unrelated embedded table.