我試圖在本地保存一些與房地產有關的信息。Ruby Data_Mapper資源無法保存 - 期待不同的數據類型
我使用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的關係?
任何幫助,非常感謝!
有趣的是,當我創建一個新的狀態時,我得到以下輸出:'=>#' 但是當我創建郊區時, >#' –
Michael