Sql Rails是一种简单的多列连接方式
rails运行以下查询的方式是什么?我找到了所有列都由未选中的列获取的答案。下面给出的查询示例:Sql Rails是一种简单的多列连接方式,sql,ruby-on-rails,ruby-on-rails-4,Sql,Ruby On Rails,Ruby On Rails 4,rails运行以下查询的方式是什么?我找到了所有列都由未选中的列获取的答案。下面给出的查询示例: select e.id, e.title, u.first_name,u.picture from events e inner join users u on e.created_by = u.id where u.id = 2 class Event < ActiveRecord::Base belongs_to:user end 我的模型如下: select e.id, e.t
select e.id, e.title, u.first_name,u.picture from events e
inner join users u
on e.created_by = u.id
where u.id = 2
class Event < ActiveRecord::Base
belongs_to:user
end
我的模型如下:
select e.id, e.title, u.first_name,u.picture from events e
inner join users u
on e.created_by = u.id
where u.id = 2
class Event < ActiveRecord::Base
belongs_to:user
end
没有将字符串隐式转换为整数
并在模板中给出以下行:
<h3><strong><%= @event["id"] %></strong></h3>
试试这个
Event.joins(:users).where("users.id = 2").select('events.id, events.title, users.first_name, users.picture')
它不工作,因为它不是在
id
上加入的,而是在事件上加入的。我尝试了此操作,但为event.id
@event=event.joins('internal JOIN users on users.id=events.created_by')提供了类型转换错误。
p.s:Qs也更新了我所做的JOIN从“events”返回查询选择“events”。*users.id=events上的内部联接用户。由
创建,但在模板中,我得到:更新后,没有将字符串隐式转换为整数:@event是一个数组,而不是散列(无论其中是否只有一条记录)