嵌套条件不返回任何结果

时间:2019-06-07 11:35:16

标签: ruby-on-rails foreign-keys relational-database datamapper

作为课程的一部分,我们正在创建AirBnB克隆。为此,我们使用DataMapper创建了链接表

class User
  include DataMapper::Resource

  property :id,          Serial
  property :email,       String,  :required => true,
                                  :unique => true,
                                  :format => :email_address
  property :password,    String, :required => true

  has n, :spaces
  has n, :bookings

end
class Space
  include DataMapper::Resource

  property :id,          Serial
  property :name,        String,  required: true
  property :description, Text,    required: true
  property :price,       Integer, required: true
  property :checkin,     Date,    required: true
  property :checkout,    Date,    required: true

  belongs_to :user
  has n, :bookings

end
class Booking
  include DataMapper::Resource

  property :id,           Serial
  property :arrival,      Date,     required: true
  property :departure,    Date,     required: true
  property :confirmed,    Boolean

  belongs_to :user
  belongs_to :space

end

我们正在尝试获取由特定用户ID创建的所有未确认(null)预订。

基于嵌套条件上的datamapper documentation,我们尝试使用外键进行以下操作:

user = session[:user]
bookings = {:confirmed => nil, :space_id => { :user_id => user.id } }
p Booking.all(bookings)

根据文档,应该返回正确的详细信息,但返回空数组。

有人可以建议如何正确嵌套条件

0 个答案:

没有答案