I broke something and now can't add properties to couchrest_model models ???

20 views
Skip to first unread message

Stephen Bannasch

unread,
May 25, 2012, 10:50:34 AM5/25/12
to couc...@googlegroups.com
I'm just starting to use couchrest_model -- and it was working -- and I feel like I must be doing something obvious and stupid
...

but ... now I can't add properties to couchrest_model models anymore ???

Obviously this is problem for my whole app but here's a very simple test case.

I have the following class:

class Md2dModel < CouchRest::Model::Base
end

In rails console I enter:

m1 = Md2dModel.new("a" => 123)
>> #<Md2dModel type: "Md2dModel">

But the property isn't added:

m1.to_json
>> "{\"type\":\"Md2dModel\"}"

If instead if I add the property directly to the model instance it works:

m1["a"] = 123
>> 123

m1.to_json
>> "{\"type\":\"Md2dModel\",\"a\":123}"

What could be going wrong??

I'm working in rails 3.2.3.

Am using my fork of couchrest 1.1.2 which just extends the gem dependency specification for the multi_json gem

gem "couchrest", :git => "git://github.com/concord-consortium/couchrest.git", :branch => "works-with-rails3.2"
gem "couchrest_model", '~> 1.1'

Stephen Bannasch

unread,
May 25, 2012, 9:24:26 PM5/25/12
to couc...@googlegroups.com
At 10:50 AM -0400 5/25/12, Stephen Bannasch wrote:
>I'm just starting to use couchrest_model -- and it was working -- and I feel like I must be doing something obvious and stupid ...
>
>but ... now I can't add properties to couchrest_model models anymore ???

Ahhh ... re-reading the fine manual (and getting some sleep) helped.

From: http://www.couchrest.info/model/properties.html

Attributes sent to #attribtues= or #update_attributes that do not have a
property definition will not be updated. This provents useless data being
passed to database, such as from an HTML form, and also because most projects
will need to do some kind of typecasting to allow the ruby code to understand
the data. However, if you would like truely dynamic attributes (CouchDB is
schema-less after all!), the mass_assign_any_attribute configuration option
when set to true will store everything you put into the mass assignment methods.

And now I remember removing list of properties I had initially placed in the model definition because I was thinking they weren't necessary ...

Here's what my model looks like now:

Md2dModel
https://github.com/concord-consortium/lab/blob/master/server/app/models/md2d_model.rb


Reply all
Reply to author
Forward
0 new messages