[Ror-es] AssociationTypeMismatch

brainstorm braincode at gmail.com
Sun Mar 18 23:01:48 GMT 2007


Hola,

Tengo un problema con

ActiveRecord::AssociationTypeMismatch: Mac expected, got String

La doc en ActiveRecord::Associations::ClassMethods es un poco escueta
al respecto:

===
Type safety with ActiveRecord::AssociationTypeMismatch

If you attempt to assign an object to an association that doesn't
match the inferred or specified :class_name, you'll get a
ActiveRecord::AssociationTypeMismatch.
===

Por qué infiere "Mac" i no String ? Al fin y al cabo en la BBDD hay
una string que representa una mac y sólo quiero que los trate como
strings :-S... los modelos afectados tienen este aspecto:

# == Schema Information
# Schema version: 7
#
# Table name: ips
#
#  id      :integer(11)   not null, primary key
#  ip      :string(255)
#  mac     :string(255)
#  zone_id :integer(11)
#  mac_id  :integer(11)
#

class Ip < ActiveRecord::Base
	has_one :mac


# == Schema Information
# Schema version: 8
#
# Table name: macs
#
#  id        :integer(11)   not null, primary key
#  mac       :string(255)
#  oid       :string(255)
#  system_id :integer(11)
#  port_id   :integer(11)
#  ip_id     :integer(11)
#
class Mac < ActiveRecord::Base
	has_many :ips

TIA !


More information about the Ror-es mailing list