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.
johan duflost (Guest)
on 2006-01-05 18: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
Ezra Z. (Guest)
on 2006-01-05 20: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 Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid
John W. (Guest)
on 2006-01-06 02:34
(Received via mailing list)
On 1/5/06, Ezra Z. <removed_email_address@domain.invalid> 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 W.
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.