Forum: Ruby on Rails model with type attribute

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
33ada38869e3bd882cfbe6799b5c822b?d=identicon&s=25 johan duflost (Guest)
on 2006-01-05 17:44
(Received via mailing list)
Dear all,

I have a table with a column named "type" and I 'd like to access the
type
field of the correspondant model object but I get a deprecation warning
when
I use the following code :

modelObject.type

"type deprecated use class instead"

How can I access such a named field in rails ?

Johan

Johan Duflost
Analyst Programmer
Belgian Biodiversity Platform ( http://www.biodiversity.be)
Belgian Federal Science Policy Office (http://www.belspo.be )
Tel:+32 2 650 5751 Fax: +32 2 650 5124
132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-01-05 19:57
(Received via mailing list)
On Jan 5, 2006, at 5:29 AM, johan duflost wrote:

>
> How can I access such a named field in rails ?
>
> Johan
>
> Johan Duflost
> Analyst Programmer
> Belgian Biodiversity Platform ( http://www.biodiversity.be)
> Belgian Federal Science Policy Office (http://www.belspo.be )
> Tel:+32 2 650 5751 Fax: +32 2 650 5124
>

Johan-

	type is a reserved word in ruby for now. So call your type field
something else like mytype or kind.


Cheers-
-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
10d9ed7ab11115b081bb36f56a7a13bc?d=identicon&s=25 John Wilger (Guest)
on 2006-01-06 01:34
(Received via mailing list)
On 1/5/06, Ezra Zygmuntowicz <ezra@yakima-herald.com> wrote:
>
> Johan-
>
>         type is a reserved word in ruby for now. So call your type field
> something else like mytype or kind.

Actually, you can just explicitely define #type and #type= in the model
class.

  class Thing < ActiveRecord::Base
    def type
      read_attribute :type
    end

    def type=( new_type )
      write_attribute :type, new_type
    end
  end

--
Regards,
John Wilger
http://johnwilger.com

-----------
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
This topic is locked and can not be replied to.