私はRuby on Railsの新機能であり、正しいクエリを作成しようとしています。しかし、ドキュメンテーションとサンプルを読んだ後、私はそれから適切なクエリを得ることはできません。だから私は誰かが正しい方向に私を指すことができることを願っています。「親」モデルのフィールドで入れ子になったアイテムを並べ替える方法は?
状況私は、トレーナーがトレーニングをセットアップし、これらのトレーニングをいくつかの日付(スリルと呼ばれる)で与えることができるアプリを構築します。他のユーザーはこれらのスリルを購読できます。
class User
has_many :trainings
has_many :thrills, through: :trainings
has_many :reservations
class Training
belongs_to :user
has_many :reservations
has_many :thrills
has_many :users, through: :thrills
class Thrill
belongs_to :training
has_many :reservations
has_many :users, through: :reservations
class Reservation
belongs_to :user
belongs_to :thrill
has_one :training, through: :thrill
がどのように私はthrilldate順CURRENT_USERのすべての予約のリストを作ることができます質問:それは次のような構造を持っていますか?スリルはスリルモデルで設定されています。私が持っている私のreservations_controller.rbで
:
@reservations = current_user.reservations
これは、すべてのreserationsの右側のリストを提供しますが、私は、このビューを使用してそうしようとしたreservation.thrill.thrilldate のリストにこれをソートしたいです:
<% @reservations.order("reservation.thrill.thrilldate ASC").each do |reservation| %>
は、残念ながら、これはエラーを与える:
SQLite3::SQLException: no such column: reservation..thrill.thrilldate: SELECT "reservations".* FROM "reservations" WHERE "reservations"."user_id" = ? ORDER BY reservation.thrill.thrilldate ASC
スリルズモデルのスリル満点をどのように参照することができますか?私を助けてくれてありがとう! thrilldate
を想定し
恐ろしいのコラムです!私はこれをビューでやろうとしていましたが、これはスーパーです。ありがとう! –