我正在构建一个Rails 3.2.6应用程序,并且在此应用程序中我获得了用户,事件和检查。 我也在使用Postgres。无法获得包含和连接在Ruby on Rails中工作
用户
has_many :events
has_many :checkins
活动
belongs_to :user
has_many :checkins
签到
belongs_to :user
belongs_to :event
当我呼吁所有CHEC (使用下面的代码)我也想要 获取签入事件的所有基本数据,但它不起作用。 我只收到签入的数据,没有任何事件。哪里不对?
current_user.checkins.includes(:event)
我想这太:
current_user.checkins.joins(:event)
UPDATE
我这样做是为了让所有的事件数据,而不是签数据。这是正确的 这样做吗?
checkins = current_user.checkins
@array = Array.new
@array = checkins.collect {|checkin| checkin.event}
render :json => {:results => @array}
看起来不错!基本上,我需要实现的是获取所有事件数据,而不是每个“签入”的签入数据并将其返回。我怎样才能做到这一点? – 2012-08-16 12:02:00
我更新了我的代码。这个代码是一个好习惯吗? – 2012-08-16 12:08:49