Column name 'key' colliding with :key

84 views
Skip to first unread message

muthu

unread,
Dec 2, 2011, 11:21:15 PM12/2/11
to DataMapper
Hi,

I have a database table called "xyz" with a column "key". But when I
try to run datamapper to save data, it throws the following:

/Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/property.rb:
739:in `initialize': +name+ was "key", which cannot be used as a p
roperty name since it collides with an existing method or a query
option (ArgumentError)
from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/
property/string.rb:32:in `initialize'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/
model/property.rb:55:in `new'
from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/
model/property.rb:55:in `property'
from /Library/Ruby/Gems/1.8/gems/dm-validations-1.2.0/lib/dm-
validations/auto_validate.rb:11:in `property'
from app.rb:26

I have a table with column name itself as "key"

How can I fix this?

Thanks in advance

Muthu

Chris Corbyn

unread,
Dec 3, 2011, 12:00:02 AM12/3/11
to datam...@googlegroups.com
I think these sorts of things are a limitation of ORMs as a concept (albeit a minor one), along with words like 'transaction' and 'index'. I try to avoiding using reserved words like `key` in my schema, but if you have to work with it, rename it to something else on the DataMapper side.

property :whatever, Integer, :field => 'key'

Cheers,

Chris

> --
> You received this message because you are subscribed to the Google Groups "DataMapper" group.
> 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.
>

muthu

unread,
Dec 3, 2011, 7:20:54 AM12/3/11
to DataMapper
Awesome, that worked.

Thanks,

Piotr Solnica

unread,
Dec 3, 2011, 7:26:14 AM12/3/11
to datam...@googlegroups.com
BTW - this shows why it's nice to have a separation between domain objects and database schema. With a proper data mapper pattern implementation you will have the ability to name your attributes however you want and map them to whatever you want.

-- 
Piotr Solnica - Senior Software Developer

Reply all
Reply to author
Forward
0 new messages