我正在尝试保存一些与我所在地区的房地产有关的信息。
我正在使用 Ruby 和 Data_Mapper gem 将数据保存到本地 MySQL 数据库。
这些模型目前看起来像这样:
class Property
include DataMapper::Resource
property :id, Serial
property :num, String
property :street, String
property :street_type, String
property :price, String
property :block_size, String
property :unimproved_value, String
property :found, DateTime
property :last_seen, DateTime
belongs_to :suburb
end
class Suburb
include DataMapper::Resource
property :id, Serial
property :name, String
property :post_code, Integer
has n, :properties
belongs_to :state
end
class State
include DataMapper::Resource
property :id, Serial
property :name, String
property :abbreviation, String
has n, :suburbs
end
我能够创建和保存属性和状态,但是当我尝试创建郊区时,我收到以下错误:
irb(main):006:0> Suburb.create(:name => "Test", :post_code => 4321)
ArgumentError: arguments may be 1 or 2 Integers, or 1 Range object, was: [:name]
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/collection.rb:390:in `[]'
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/model/property.rb:236:in `name='
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:336:in `block in attributes='
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:332:in `each'
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:332:in `attributes='
from /var/lib/gems/1.9.1/gems/dm-core-1.2.1/lib/dm-core/resource.rb:755:in `initialize'
from /var/lib/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `new'
from /var/lib/gems/1.9.1/gems/dm-validations-1.2.0/lib/dm-validations.rb:129:in `create'
from (irb):6
from /usr/bin/irb:12:in `<main>'
这个错误是因为我在创建对象时也没有定义状态吗?我为属性尝试了不同的数据类型,但仍然收到相同的错误。我唯一能从中得到的可能是因为我有一个 belongs_to 和 has_many 关系?
任何帮助是极大的赞赏!