contentful_model icon indicating copy to clipboard operation
contentful_model copied to clipboard

How to update an entry with empty fields?

Open julianrubisch opened this issue 6 years ago • 5 comments

I have got a feeling that I'm missing something very basic here, please pardon me.

I have a very basic CTF model with some string attributes, some of which are not required, i.e. empty.

With return_nil_for_empty I can have their values be coerced to nil, but as it seems there's no way of setting them? I get NoMethodErrors for every attr_writer to a non-required field that is blank, hence not returned by the contentful API.

julianrubisch avatar Oct 09 '18 11:10 julianrubisch

Hey @julianrubisch,

If you want to write for attributes that are empty, currently the way of doing it is:

management_entry = entry.to_management

management_entry.the_empty_field = 'some value'

management_entry.save

I'll add an issue to our backlog to forward this functionality to the contentful_model entry wrapper, so that you don't need to directly interact with the underlying management object, but cannot promise exactly when this would be completed.

Hope this workaround works for you,

Cheers

dlitvakb avatar Oct 09 '18 13:10 dlitvakb

thanks, that clarifies it a little :)

Though now I'm seeing something like https://github.com/contentful/contentful_model/issues/116 ... (undefined method version= for nil:NilClass) quite randomly...

Anything I can do to help?

julianrubisch avatar Oct 09 '18 14:10 julianrubisch

Have you tried what I said in that thread?

Cheers

dlitvakb avatar Oct 09 '18 15:10 dlitvakb

Yep well, it’s the same to_management method, isn’t it?

julianrubisch avatar Oct 09 '18 15:10 julianrubisch

Yes, that's correct.

Cheers

dlitvakb avatar Oct 09 '18 15:10 dlitvakb