Dan, does the same thing happen if I call create(attributes)? I'd like
to avoid having to use two lines of code where one will do. I had set
up the db constraint but not the validation. Didn't think it mattered.
I will go ahead and do that.

On Sat, Feb 27, 2010 at 11:21 AM, Dan Kubb (dkubb) <dan.k...@gmail.com> wrote:
> Dirkjan,
>
>> Doesn't this work like you want:
>>
>> o = SomeObject.new(:attribute => 'value')
>> o.save
>>
>> Resource#save returns true or false here, but you're of course welcome
>> to ignore that return value.
>
> Yeah, that's what I was getting at. This only works if you have
> uniqueness validation turned on. If there's no DB constraint, and dm-
> validations is off, you'll get an explosion. With no DB constraint
> *or* validations, it'll just insert a new record. With uniqueness
> constraints turned on DM will not perform the insert at all, because
> it'll see the record already exists, and it will return false; which
> you are free to ignore.
>
> However, based on the StackOverflow thread it appears as if Carl found
> a work-around using #first_or_create. I forgot to recommend this
> because I got caught up on the requirement "silently fail if a record
> with the same name already exists", which to me implied that he wanted
> to save the record and have the operation be a no-op if the record
> already exists.
>
> --
>
> Dan
> (dkubb)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "DataMapper" group.
> To post to this group, send email to datamap...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to datamap...@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