gpt4 book ai didi

mysql - Ruby Data_Mapper 资源无法保存 - 需要不同的数据类型

转载 作者:行者123 更新时间:2023-11-29 13:32:06 24 4
gpt4 key购买 nike

我正在尝试保存一些与我所在地区的房地产相关的信息。

我使用 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关系?

非常感谢任何帮助!

最佳答案

问题出在 Suburbs 模型中引用 Properties 时的拼写问题。正确的拼写(根据 Ruby)是 Propertys

关于mysql - Ruby Data_Mapper 资源无法保存 - 需要不同的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19286976/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com