Tag: datamapper

Datamapper成为String

我希望能够在我的数据库中看到类似TwitchTV名称的字符串。 这是我目前的代码 get ‘/watch/:id’ do |id| erb :mystream @result = Twitchtvst.all( :fields => [:Twitchtv ], :conditions => { :user_id => “#{id}” } ) puts @result end 结果终端; # 如何将其转换为字符串(数据库中的TwitchTV答案) Opppppsss! 这是真正的代码示例。 抱歉! get ‘/livestream’ do erb :livestream @users_streams = Twitchtvst.all puts @users_streams end 如果我在users_stream添加.to_s则不起作用

Sinatra将params 与字符串类型匹配,需要额外的转换才能匹配数据库ID?

我正在使用sinatra和DataMapper来访问sqlite3数据库。 当调用get(params[:id])时,我总是得到一个nil 。 但是当我打电话给get(params[:id].to_i)我可以得到正确的记录。 是否有任何错误,我必须明确地进行转换? sinatra应用程序很简单: class Record include DataMapper::Resource property :id, Serial …. end get ‘/list/:id’ do r = Record.get(params[:id]) … end

一对一的DataMapper关联

我是DataMapper的新手,我正在尝试为以下场景创建模型: 我有很多用户(有用户名,密码等),也可以是玩家或裁判或两者兼而有(所以单表inheritance不是一个选项)。 基础模型将是: class User include DataMapper::Resource property :id, Serial # Other user properties go here end class Player include DataMapper::Resource property :id, Serial # Other player properties go here # Some kind of association goes here end class Referee include DataMapper::Resource property :id, Serial # Other referee properties go here # Some kind of […]

DataMapper因关系而无法删除记录

我有许多使用Torrent和Tag的DataMapper / MySQL设置,如下所示: class Torrent include DataMapper::Resource property :id, Serial property :name, String property :magnet, Text property :created_at, DateTime has n, :tags, :through => Resource end class Tag include DataMapper::Resource property :id, Serial property :name, String property :hits, Integer has n, :torrents, :through => Resource end 但是,当试图通过Torrent.first.destroy或类似的东西来破坏一个torrent时,DataMapper会返回false 。 我尝试了直接的SQL查询,例如delete from torrents where name like ‘%ubuntu%’ […]

通过DataMapper从SQLite内存DB中没有这样的表错误

我有一个Ruby程序,它使用DataMapper作为ORM来与内存中的SQLite DB进行通信。 这一直很好,但我刚刚添加了一个新的DM类和相应的表。 令我惊讶的是,在auto_migrate中,事情现在爆炸了! 这是DataMapper生成的SQL: ~ (0.000390) PRAGMA table_info(“sensationd_channels”) ~ (0.000010) PRAGMA table_info(“sensationd_commands”) ~ (0.000009) PRAGMA table_info(“sensationd_configurations”) ~ (0.000052) PRAGMA table_info(“sensationd_measurements”) ~ (0.000028) SELECT sqlite_version(*) ~ (0.000035) DROP TABLE IF EXISTS “sensationd_channels” ~ (0.000009) PRAGMA table_info(“sensationd_channels”) ~ (0.000423) CREATE TABLE “sensationd_channels” (“id” INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, “channel” INTEGER NOT NULL, “name” VARCHAR(50), “precision” […]

使用dm-accepts_nested_attributes和dm-is-tree在rails中的2个模型的嵌套表单

我有两个模型:论坛应用程序中的post和图像,其中post使用dm-is-tree以父子格式排列。 在这一点上,图像已成为Post模型的一部分。 由于Post模型变得笨拙并且我需要添加更多深度来表示图像,我正在努力将Image分离到它自己的模型中,但仍然是输出中的post的一部分。 所以我开始以简单的方式集成dm-accepts_nested_attributes: class Post include DataMapper::Resource property :id, Serial property :istop, String property :created_at, DateTime property :updated_at, DateTime property :content, Text has n, :images accepts_nested_attributes_for :images is :tree, :order => [:istop, :created_at] class Image include DataMapper::Resource property :id, Serial property :created_at, DateTime belongs_to :post property :image, String, :auto_validation => false # Carrierwave image […]

如何告诉DataMapper对DateTime属性使用“timestamp with time zone”?

默认情况下,DataMapper在PostgreSQL中创建timestamp without time zone类型的DateTime属性。 我想将我的项目的默认值更改timestamp with time zone 。 如何才能做到这一点?

Heroku和Datamapper问题

我可以在Heroku上启动一个基本应用程序,显示带有’/’的消息…工作得很好。 但是,每当我尝试使用datamapper添加sqlite时,事情就会崩溃。 要查看我的应用程序结构,请查看github上的项目。 我保持代码相当简陋。 在heroku的日志中我得到: 2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require’: no such file to load — dm-postgres-adapter (LoadError) 关于这一点的是我没有使用postgres,所以我很困惑为什么这么说。

DataMapper:创建新记录或更新现有记录

DataMapper是否提供了一种在不存在或更新现有记录时创建新记录的便捷方法? 我在API文档中找不到任何内容。 这就是我目前看来并不优雅的东西: foo = Foo.get(id) if foo.nil? foo = Foo.create(#attributes…) else foo.update(#attributes…) end foo.save

如何使用DataMapper仅获取模型的指定字段?

我无法找到在特定上下文中仅获取必要的模型字段的方法。 让我们说我有一个巨大的模型,有大约30个领域(属性)。 但是出于搜索目的,我只需要几个。 例: class Foo include DataMapper::Resource property :id, Serial property :title, String, :length => 256 property :description, Text property :url, String, :length => 4096 property :city, String, :length => 64 property :country, String, :length => 64 property :state, String, :length => 64 property :created_at, Time property :updated_at, Time property :expires_at, Time … etc […]