I forgot to give an explanation of why DM behaves like that. It's
probably trivial, but why not add it here for completeness.

If you have a resource in memory, but you don't know it's key, there's
no way to persist it back to the datastore.

On Mon, Jan 10, 2011 at 16:52, Martin Gamsjaeger <[email protected]> wrote:
> To add to what Jonathan said, if you *retrieve* a resource without
> it's key, you get back an immutable resource too.
>
> So if you have a Person model with a Serial id and you do something like:
>
> Person.all(:job => 'coder', :fields => [ :name ])
>
> you will get back a Collection of immutable resources, because you've
> told it specifically to not include the key property (:id)
>
> cheers
> snusnu
>
> On Mon, Jan 10, 2011 at 16:39, Jonathan Stott <[email protected]> 
> wrote:
>> Also, you will retreive an immutable resource if you define a Model
>> without a key.
>>
>> To check for this (and to initialize relationships), you should always
>> run DataMapper.finalize after defining all your models.
>>
>> Regards
>> Jon
>>
>> On 10 January 2011 15:23, Zhi-Qiang Lei <[email protected]> wrote:
>>> Dear All,
>>>
>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>>>
>>> Best regards,
>>> Zhi-Qiang Lei
>>> [email protected]
>>>
>>> --
>>> 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.
>>>
>>>
>>
>> --
>> 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.
>>
>>
>

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