Then I could avoid creating a custom update-function, for complex forms.

2008/8/26 Abdul-Rahman Advany <[EMAIL PROTECTED]>:
>
> Why not u.library.update_attributes?
>
> On 26 aug, 02:41, "harry jr." <[EMAIL PROTECTED]> wrote:
>> Hello. Suppose I have this model:
>>
>> class User
>>   include DataMapper::Resource
>>   property :id, Integer, :serial => true
>>   property :name, String
>>
>>   has 1, :library
>>   has n, :books
>> end
>>
>> class Library
>>   include DataMapper::Resource
>>   property :id, Integer, :serial => true
>>   property :name, String
>>
>>   belongs_to :user
>> end
>>
>> class Book
>>   include DataMapper::Resource
>>   property :id, Integer, :serial => true
>>   property :title, String
>>
>>   belongs_to :user
>> end
>>
>> Then I can do this in IRB:
>>
>> > u = User.create(:name => "harry", :library => {:name => 'West Side'}, 
>> > :books => [{:title => "How to Win"}, {:title => "How Not to Lose"}])
>>
>> => #<User id=4 name="harry" password=nil>>> u.library
>>
>> => #<Library id=4 name="West Side" user_id=4>>> u.books
>>
>> => [#<Book id=4 title="How to Win" user_id=4>, #<Book id=5 title="How
>> Not to Lose" user_id=4>]>> u.update_attributes(:library => {:name => 'East 
>> Side'})
>> => true
>> >> u.library
>>
>> => #<Library id=5 name="East Side" user_id=4>
>>
>> But how would i do a u.update_attribtues to change the title of book
>> with id 5 to 'My Story' ?
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to