Hi Neil C

I try to redo your case, so here:

ruby-1.9.3-p0 :022 > Person.first
 => #<Person @id=1 @name="arthur">
ruby-1.9.3-p0 :023 > Person.first.photos
 => [#<Photo @id=2 @url="b skeleton" @person_id=1>, #<Photo @id=3 @url="c
wizard" @person_id=1>, #<Photo @id=4 @url="a amazon" @person_id=1>]
ruby-1.9.3-p0 :024 > Person.first.photos.all(:url.like => '%amazon%')
 => [#<Photo @id=4 @url="a amazon" @person_id=1>]
ruby-1.9.3-p0 :025 > Person.first.photos.all(:url.like =>
'%amazon%').destroy
 => true
ruby-1.9.3-p0 :026 > Person.first.photos.all(:url.like => '%amazon%')
 => []
ruby-1.9.3-p0 :027 > Person.first.photos.all
 => [#<Photo @id=2 @url="b skeleton" @person_id=1>, #<Photo @id=3 @url="c
wizard" @person_id=1>]
ruby-1.9.3-p0 :028 > Photo.all
 => [#<Photo @id=2 @url="b skeleton" @person_id=1>, #<Photo @id=3 @url="c
wizard" @person_id=1>]
ruby-1.9.3-p0 :029 >

Apparently it'd functioned. Is that what you want ?
Anyway, I'm using datamapper 1.1.0

so long

2012/8/23 Neil C <n...@vidyasource.com>

> I caught the typos with the % sign after I posted. Still, as you said,
> that wouldn't cause the error but rather just not destroy anything.
>
> I am using DM_VERSION = "~> 1.2.0". Basically, I cut and pasted what's in
> the dm-rails. I am not sure how you managed to make it work.
>
> I have things working in a pure SQL way now, but any insight will be
> helpful.
>
> Thanks.
>
>
> On Wednesday, August 22, 2012 6:52:20 PM UTC-4, Chris Corbyn wrote:
>
>> Way less readable and elegant though ;)  This is a bug.  DataMapper
>> should know that URI properties are dumped to strings, so that should be
>> what it does when it generates the query.
>>
>> That said, your original query is wrong.  It should have the '%' marks
>> around the search string:
>>
>> person.photos.all(:url.like => '%amazon%').destroy
>>
>> What version of DM are you using?  I just tried this with a model we use
>> URI types on and it worked as expected.  I tried it both directly on the
>> model, and by going through a 1:m relationship. (DM 1.2.0).
>>
>>
>> Il giorno 23/ago/2012, alle ore 03:14, Abe Voelker ha scritto:
>>
>> Also from your example it looks like DM is pulling in the url field as
>> an Addressable::URI, so it is probably already fetching all the associated
>> records from the DB in order to load them into memory to parse
>> into Addressable::URI structures.  If that's the case, then I don't think
>> there would be any additional performance overhead from what you originally
>> had to just doing
>>
>> person.photos.all.select{|**photo| photo.url.host.downcase == 'amazon.com
>> '}
>>
>> On Wednesday, August 22, 2012 12:01:05 PM UTC-5, Abe Voelker wrote:
>>>
>>> Is this too SQL-ish?
>>>
>>> person.photos.all(:conditions => ['"url" ilike ?', "%amazon%"])
>>>
>>> On Wednesday, August 22, 2012 11:48:23 AM UTC-5, Neil C wrote:
>>>>
>>>> Besides, obviously, a SQL solution.
>>>>
>>>> Thanks.
>>>>
>>>>
>>>>
>>>> On Wednesday, August 22, 2012 12:45:52 PM UTC-4, Neil C wrote:
>>>>>
>>>>> I am trying to do the following:
>>>>>
>>>>> person.photos.all(:url.like => "amazon").destroy
>>>>>
>>>>> As you might guess, 1 person has n photos, and each photo has a url
>>>>> property. I am trying to remove any photos with "amazon" in the URL.
>>>>>
>>>>> When I do this, I get the following:
>>>>>
>>>>> NoMethodError: undefined method `gsub' for 
>>>>> #<Addressable::URI:**0x3fc672305d40
>>>>> URI:amazon>
>>>>>
>>>>> Any insight into solving this is appreciated.
>>>>>
>>>>> Thanks.
>>>>>
>>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "DataMapper" group.
>> To view this discussion on the web visit https://groups.google.com/d/**
>> msg/datamapper/-/K0BzmeduifoJ<https://groups.google.com/d/msg/datamapper/-/K0BzmeduifoJ>
>> .
>> To post to this group, send email to datam...@googlegroups.com.
>> To unsubscribe from this group, send email to datamapper+...@**
>> googlegroups.com.
>>
>> For more options, visit this group at http://groups.google.com/**
>> group/datamapper?hl=en <http://groups.google.com/group/datamapper?hl=en>.
>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/datamapper/-/tu1FnD7DyuwJ.
>
> 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.
>



-- 
------------------------------------------
 1. Notebook para você ficar livre e programar a vontade: R$ 2300
 2. Curso de Programação/SysAdmin/DBA: R$ 5000
 3. Pedir a solução pronta para um problema numa lista de discussão: Não
tem preço !

E para todas as outras existe RTFM, STFW e  LMGTFY

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