3

I've some trouble with a really simple Rails setup using DataMapper. This is my model:

class Capture
  include DataMapper::Resource
  property :id, Serial
  property :identifier, String
  property :caption, Text
 end

Now I add a new capture in Rails console by:

Capture.create(:identifier => '12345', :caption => 'Foo bar foo')

If I try to get all captures by

Capture.all

... i get a

[#<Capture @id=1 @identifier="12345" @caption=<not loaded>>]

First question: what does the "not loaded" mean in this case? But the trouble I have is I cannot convert the result to JSON:

Capture.all.to_json

NoMethodError: undefined method `encode_json' for #<Capture @id=1 @identifier="12345" @caption=<not loaded>>

Is it a DM issue? How to encapsulate such a result into JSON? Many thanks in advance ;-) Chris.

tereško
  • 56,151
  • 24
  • 92
  • 147
ctp
  • 1,025
  • 1
  • 7
  • 27

1 Answers1

1

The answer for the first question: not loaded means that data loading is delayed until actually needed because Text property is lazy by default. http://datamapper.org/articles/spotlight_on_laziness.html

ujifgc
  • 2,075
  • 1
  • 18
  • 20