1

I have a rails 3 application and I am fairly new to rails. I have an address model. When a form gets submitted, the address is saved successfully. In the address model, there is a field as follows:

property :street_address, Text, :required => true

In the rails console, when I type:

1.9.3p194 :062 > add  = Address.get(208)
 => #<Address @id=208 @street_address=<**not loaded**> @postal_code="400123" @latitude=0.0            @longitude=0.0 @sub_area="subarea1" @city_id=1 @state_id=16 @country_id=1 @area_id=nil> 
1.9.3p194 :063 > add.street_address
 => "STREET" 

Why is " not loaded " displayed for street address? Same thing happens for a field of Text data type in another model.

Lars Haugseth
  • 14,721
  • 2
  • 45
  • 49
arkiver
  • 465
  • 1
  • 5
  • 11

2 Answers2

0

With DataMapper, some properties (for instance those of type Text), are by default lazy loaded, ie. they are not fetched from the database until they are being accessed by your code.

You can override this behaviour by adding :lazy => false to a property in your model definition.

For more detailed information, consult the documentation. There is a section there titled Lazy Loading.

Lars Haugseth
  • 14,721
  • 2
  • 45
  • 49
0

DataMapper lazy-loads some data types to make database queries faster. This means that fields with a lot of data (like Text attributes) won't be loaded until they are required

Text fields are lazily loaded by default, which you can over-ride if you need to.

property :street_address, Text, :required => true, :lazy => false
Bijendra
  • 9,467
  • 8
  • 39
  • 66