On 10/19/2009 10:18 AM, Dan Kubb (dkubb) wrote:
> MilesTogue,
>
>    
>> # db has one user,  no contacts yet
>>
>> @user = User.first # returns first user
>> if @user.contacts =>  error condition dependent does not map to
>> relationship in Contact
>>
>> shouldn't it return false ?  I can wrap this with a test for contacts
>> but like to avoid extra code if possible.
>>      
> This should return an empty Collection (a Collection is like an Array
> of persisted resources).
>
> In this case you want to use Collection#any? and Collection#empty?
> (inherited from Enumerable), eg:
>
>    if @user.contacts.any?
>      #  do something if there are *any* contacts
>    end
>
>    if @user.contacts.empty?
>      # do something if there are *no* contacts
>    end
>
>    

hmm, thks for info but I tried both  @user.contacts.any?  also  
!...@user.contacts.empty?
both gave same error as before - running datamapper 0.10.1  - I'll 
experiment (add a contact, delete it...)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to datamapper@googlegroups.com
To unsubscribe from this group, send email to 
datamapper+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to