Hi When i try to serialize an ActiveRecord object it doesn''t save the id-property of the modell. class ModelA < ActiveRecord :serialize model_b end model_b_obj = ModelB.find(1) model_a = ModelA.new model_a.model_b = model_b_obj model_a.save model_a.model_b.id -> "" I assume it has something to do with visibility of class ModelA... Do I have to override some properties from ActiveRecord? Thanks! Kristian H
On 7/11/05, Kristian Hellquist <kristian-fwIc/cu1KZxHQX+h2pknIQ@public.gmane.org> wrote:> Hi > > When i try to serialize an ActiveRecord object it doesn''t save the > id-property of the modell. > > class ModelA < ActiveRecord > :serialize model_b > end > > model_b_obj = ModelB.find(1) > model_a = ModelA.new > model_a.model_b = model_b_obj > model_a.save > > model_a.model_b.id -> "" > > I assume it has something to do with visibility of class ModelA... Do I > have to override some properties from ActiveRecord? > > Thanks! > Kristian HDoes model.save return true or false? After attempting to save, what does model.errors.full_messages give you? -- rick http://techno-weenie.net
Kristian Hellquist
2005-Jul-11 18:21 UTC
Re: Marshaling model-objects wont save id property
mån 2005-07-11 klockan 13:06 -0500 skrev Rick Olson:> On 7/11/05, Kristian Hellquist <kristian-fwIc/cu1KZxHQX+h2pknIQ@public.gmane.org> wrote: > > Hi > > > > When i try to serialize an ActiveRecord object it doesn''t save the > > id-property of the modell. > > > > class ModelA < ActiveRecord > > :serialize model_b > > end > > > > model_b_obj = ModelB.find(1) > > model_a = ModelA.new > > model_a.model_b = model_b_obj > > model_a.save > > > > model_a.model_b.id -> "" > > > > I assume it has something to do with visibility of class ModelA... Do I > > have to override some properties from ActiveRecord? > > > > Thanks! > > Kristian H > > Does model.save return true or false? > After attempting to save, what does model.errors.full_messages give you? >it results true. In the database the row is stored something like: id | document_id | user_id | content_id | data | instance_id ----+-------------+---------+------------+---------------------------+------------- 28 | 20 | 2 | 1 | --- !ruby/object:Article attributes: name: bajs preamble: lök text: lökölk url: "ölkölk" new_record: true | 20 What I am missing in the YAML-representation is the attribute "id".