From: Dave Howell on

On Jun 10, 2010, at 1:56 , Brian Candler wrote:
>
>
> The AR documentation is pretty comprehensive. All I needed was to find
> self.table_name = ...
> self.primary_key = ...
> and to look at the options provided by belongs_to/has_many.

The piece I couldn't find was "How do I tell ActiveRecord to convert the database's "UUID" type to a string, and vice versa?"
From: Brian Candler on
Dave Howell wrote:
> The piece I couldn't find was "How do I tell ActiveRecord to convert the
> database's "UUID" type to a string, and vice versa?"

Ah, I've never come across a database with a "UUID" type. I'd imagine AR
would treat unknown types as strings, but you'd need to try it.
--
Posted via http://www.ruby-forum.com/.

From: Dave Howell on

On Jun 11, 2010, at 0:48 , Brian Candler wrote:

> Dave Howell wrote:
>> The piece I couldn't find was "How do I tell ActiveRecord to convert the
>> database's "UUID" type to a string, and vice versa?"
>
> Ah, I've never come across a database with a "UUID" type. I'd imagine AR
> would treat unknown types as strings, but you'd need to try it.

I had to hook a special library into Postgres in order to get the UUID type. Everybody (including me) expects AR to treat it as a string, but in fact, it threw an error because the column was an unknown type. That's why I was trying to figure out how to *tell* it to treat it as a string.



From: Walton Hoops on
On 6/11/2010 2:36 AM, Dave Howell wrote:
> On Jun 11, 2010, at 0:48 , Brian Candler wrote:
>
>
>> Dave Howell wrote:
>>
>>> The piece I couldn't find was "How do I tell ActiveRecord to convert the
>>> database's "UUID" type to a string, and vice versa?"
>>>
>> Ah, I've never come across a database with a "UUID" type. I'd imagine AR
>> would treat unknown types as strings, but you'd need to try it.
>>
> I had to hook a special library into Postgres in order to get the UUID type. Everybody (including me) expects AR to treat it as a string, but in fact, it threw an error because the column was an unknown type. That's why I was trying to figure out how to *tell* it to treat it as a string.
>
Worth noting: the error you supplied clearly came from running a
migration ("Could not create table blahblahblah. Unrecognized data type
UUID.") NOT accessing a table.

From: Walton Hoops on
On 6/11/2010 2:36 AM, Dave Howell wrote:
> On Jun 11, 2010, at 0:48 , Brian Candler wrote:
>
>
>> Dave Howell wrote:
>>
>>> The piece I couldn't find was "How do I tell ActiveRecord to convert the
>>> database's "UUID" type to a string, and vice versa?"
>>>
>> Ah, I've never come across a database with a "UUID" type. I'd imagine AR
>> would treat unknown types as strings, but you'd need to try it.
>>
> I had to hook a special library into Postgres in order to get the UUID type. Everybody (including me) expects AR to treat it as a string, but in fact, it threw an error because the column was an unknown type. That's why I was trying to figure out how to *tell* it to treat it as a string.
>
Strange, my version of Postgre (8.4) comes with a UUID type.
Anyway since this seems to be something we're going back and forth on
have a look at:
http://gist.github.com/434783

The output from this script will be (using Ruby 1.9.1 and PostgreSQL 8.4):
bar
foo

Sure enough, a UUID gets treated just like a string.