私はRubyを始めたばかりです。私は Sinatra で小さなアプリを作成しており、sqlite3 db で Datamapper を使用しています。
以下は、私が作成している 3 つのモデルです。
class Team
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :created_at, DateTime
property :updated_at, DateTime
end
class Poll
include DataMapper::Resource
property :id, Serial
property :name, String, :required => true
property :created_at, DateTime
property :updated_at, DateTime
end
class Ranking
include DataMapper::Resource
property :year, Integer
property :week, Integer
property :ranking, Integer
property :votes, Integer
property :created_at, DateTime
property :updated_at, DateTime
belongs_to :team, :key => true
belongs_to :poll, :key => true
end
私ができるようにしたいのは、特定の投票、週、年についてランキング モデルをクエリすることです。
返される結果は、各ランキング番号に関連付けられたチームのその投票のすべてのランキングである必要があります。
したがって、たとえば 2011 年 - 第 1 週または 2011 年 - 第 7 週などのランキングと、各ランキングに対応するチームを取得します。
私は一日中これを機能させる方法を見つけようとしてきましたが、どこにも行きません。そのため、ここに投稿して助けを求めています.