rails columns name conflict

J

jm

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

John Wilger

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
 
C

Caleb Tennis

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
 
J

jm

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,462
Latest member
ChanaLipsc

Latest Threads

Top