ruby-on-rails - 我不确定我的查询语句有什么不正确的地方
问题描述
这是我写的查询语句。我正在尝试获取并打印所有帖子的价值requestor == current_user.id
@posts = Post.joins(user: :follows).where(follows: { requestor: current_user.id }).order(created_at: :desc)
目前,此查询语句仅打印出 的帖子current.id
并将每个帖子乘以列出的请求者数量。
requestor
是:follows
包含 a 的表的一部分user.id
。我将在下面发布以下内容和发布表格。用户的表使用基本设计。
# Table name: follows
#
# id :bigint not null, primary key
# following :bigint
# requestor :bigint
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint
#
# Indexes
#
# index_follows_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
# Table name: posts
#
# id :bigint not null, primary key
# attachment :string
# content :text
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint
#
# Indexes
#
# index_posts_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
任何帮助将不胜感激!
这是视图循环。
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Attachment</th>
<th>Content</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @posts.each do |post| %>
<%= content_tag :tr, id: dom_id(post), class: dom_class(post) do %>
<td><%= post.attachment %></td>
<td><%= post.content %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<% end %>
<% end %>
</tbody>
</table>
</div>
解决方案
推荐阅读
- c++ - c++ 关于模板参数的协变构造
- javascript - 尝试在 Mongoose 中使用 .find() 时出错
- git - Git 尝试推送不再位于 repo 或缓存中的超大文件
- html - 在视频剪辑上叠加文本
- javascript - 在第一页打开时捕获引导选项卡事件
- excel - Excel 公式帮助:从一个表中查找/匹配字符串字段与另一个表
- html - 有没有办法将我的 h1 设置在段落的顶部,因为我使用 display flex 垂直设置它们
- c# - 你能给我解释一下这段代码吗:Public Class MainPageViewModel : INotifyPropertyChanged {}
- javascript - 如何从htmlelement中求和整数
- r - 在 GoogleFonts 中使用粗体字