Hi,
I have a question about lazy loading.
If lazy loaging is enabled,
object.attr = 'new value'
object.save
doens't work correctly (= UPDATE statement is not submitted).
Is it intended spec?
How to (wth merb):
### create a model with lazy loading enabled
$ merb-gen model post
$ vi app/models/post.rb
$ cat app/models/post.rb
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :nullable => false, :length => 255
property :body, Text, :nullable => false
end
### create object and try to change property value
$ rake db:autoupgrade
$ merb -i
>> Post.create(:title=>"Title1", :body=>"Body1")
Thu, 27 Nov 2008 01:46:22 GMT ~ debug ~ INSERT INTO `posts`
(`body`, `title`) VALUES ('Body1', 'Title1')
=> #<Post id=1 title="Title1" body="Body1">
>> post1 = Post.get(1)
Thu, 27 Nov 2008 01:47:00 GMT ~ debug ~ SELECT `id`, `title` FROM
`posts` WHERE (`id` = 1) ORDER BY `id` LIMIT 1
=> #<Post id=1 title="Title1" body=<not loaded>>
>> post.title = "XXX" ## I changed post title,
=> "XXX"
>> post1.save ## but UPDATE statment is not submitted
Thu, 27 Nov 2008 01:48:03 GMT ~ debug ~ SELECT `body`, `id`,
`title` FROM `posts` WHERE (`id` = 1) ORDER BY `id`
=> true
>> post1.title ## and changed data is not saved
=> "Title1"
### change model definition to lazy loading disabled
$ vi app/models/post.rb
$ cat app/models/post.rb
class Post
include DataMapper::Resource
property :id, Serial
property :title, String, :nullable => false, :length => 255
property :body, Text, :nullable => false, :lazy => false
## add :lazy => false
end
### changed propety value seems to be saved with no problem
$ rake db:autoupgrade
$ merb -i
>> post1 = Post.get(1)
Thu, 27 Nov 2008 02:05:41 GMT ~ debug ~ SELECT `id`, `title`,
`body` FROM `posts` WHERE (`id` = 1) ORDER BY `id` LIMIT 1
=> #<Post id=1 title="Title1" body="Body1">
>> post1.title = "XXX" ## I change property
=> "XXX"
>> post1.save ## and UPDATE statement is submitted!
Great!
Thu, 27 Nov 2008 02:05:56 GMT ~ debug ~ UPDATE `posts` SET `title`
= 'XXX' WHERE (`id` = 1)
=> true
Can you help me?
--
regards,
makoto kuwata
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---