[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rails columns name conflict

jm

3/23/2005 5:43:00 AM

A question for the rails users out there.

Rails error:

....This error is raised because the column 'type' is reserved for
storing the class in case of inheritance. Please rename this column if
you didn't intend it to be used for storing the inheritance class or
overwrite Record.inheritance_column to use another column for that
information.

I fixed this by adding

def self.inheritance_column
"rails_type"
end

to the model class which may not be the correct fix, but at least it
let me work on it a bit more. Anyway, the row name "type"
clashes/conflicts with the ruby method of the same name. Is there a way
to change the row mappings so that db column type maps to/from
Record.rectype or something similar?

And, before you say change the row name I didn't pick the database
schema and it's used by another program which has this compiled in.

thanks,
J.



3 Answers

John Wilger

3/23/2005 5:53:00 AM

0

On Wed, 23 Mar 2005 14:43:10 +0900, jm <jeffm@ghostgun.com> wrote:
> to the model class which may not be the correct fix, but at least it
> let me work on it a bit more.

That is the correct fix.

> Anyway, the row name "type"
> clashes/conflicts with the ruby method of the same name. Is there a way
> to change the row mappings so that db column type maps to/from
> Record.rectype or something similar?

It shouldn't be a problem since Object#type is a deprecated method in
Ruby. I'd suggest just sticking with #type unless you run into some
specific problem.

--
Regards,
John Wilger

-----------
Alice came to a fork in the road. "Which road do I take?" she asked.
"Where do you want to go?" responded the Cheshire cat.
"I don't know," Alice answered.
"Then," said the cat, "it doesn't matter."
- Lewis Carrol, Alice in Wonderland


Caleb Tennis

3/23/2005 11:42:00 AM

0

> to the model class which may not be the correct fix, but at least it
> let me work on it a bit more. Anyway, the row name "type"
> clashes/conflicts with the ruby method of the same name. Is there a way
> to change the row mappings so that db column type maps to/from
> Record.rectype or something similar?

You can work around this by doing something like this in your model:

def type
read_attribute("type")
end

def type=(a)
write_attribute("type", a)
end


jm

3/23/2005 10:35:00 PM

0


On 23/03/2005, at 10:42 PM, Caleb Tennis wrote:
>
> You can work around this by doing something like this in your model:
>
> def type
> read_attribute("type")
> end
>
> def type=(a)
> write_attribute("type", a)
> end
>
Thanks. This is exactly what I was after. I just check and it seems to
work. I thought it would be possible to override the method but didn't
know what with nor did I wish to ask a leading question. thanks also to
john for confirming that self.inheritance_column() was correct as I'd
done this by reading between the lines.

J.