contentful / contentful_model

A lightweight wrapper around the Contentful api gem, to make it behave more like ActiveRecord
MIT License
44 stars 42 forks source link

How to update an entry with empty fields? #123

Open julianrubisch opened 6 years ago

julianrubisch commented 6 years ago

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.

dlitvakb commented 6 years ago

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

julianrubisch commented 6 years ago

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?

dlitvakb commented 6 years ago

Have you tried what I said in that thread?

Cheers

julianrubisch commented 6 years ago

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

dlitvakb commented 6 years ago

Yes, that's correct.

Cheers