Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Rails是一种简单的多列连接方式_Sql_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Sql 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

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.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是一个数组,而不是散列(无论其中是否只有一条记录)