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.

3
  • OK, found it out: to use to_json in DataMapper I need dm-serializer as Gem. Works fine now ;-) Commented May 8, 2011 at 1:26
  • 3
    You should answer your own question and accept it. Commented May 8, 2011 at 1:30
  • @Simon's right, instead of adding [SOLVED] to the title of your answer, just answer your own question and accept it. Commented May 8, 2011 at 1:31

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.