diese Verbände gegeben ...Rails plündern und Selbst Join Verbände Abfrage
class User < ActiveRecord::Base
has_many :orders
has_many :followers, through: :follower_follows, source: :follower
# follower_follows "names" the Follow join table for acessing through the follower association
has_many :follower_follows, foreign_key: :followee_id, class_name: "Follow"
has_many :followees, through: :followee_follows, source: :followee
# followee_follows "names" the Follow join table for accessiing through the followee association
has_many :followee_follows, foreign_key: :follower_id, class_name: "Follow"
end
class Order < ActiveRecord::Base
belongs_to :user
end
... und einen Controller ...
class OrdersController < ApplicationController
def index
@q = Order.ransack(params[:q])
@orders = @q.result.includes(:user, :followers)
# I'am not sure if the includes method is corrects
end
end
... in meine Ansichten ...
<%= search_form_for @q do |f| %>
<%= f.label :user_id_eq %>
<%= f.search_field :user_id_eq %>
<%= f.submit "search" %>
<% end %>
ich habe dieses Szenario:
Benutzer mit ID = 1 => Manager-Rolle
Benutzer mit ID = 2 => Anhänger user_id = 1
Benutzer mit ID = 3 => Anhänger user_id = 1
# select * from follows;
id | follower_id | followee_id | created_at | updated_at
----+-------------+-------------+----------------------------+----------------------------
1 | 2 | 1 | 2017-12-09 22:30:03.299006 | 2017-12-09 22:30:03.299006
2 | 3 | 1 | 2017-12-09 22:30:03.304564 | 2017-12-09 22:30:03.304564
Die Frage ist:
Howto setup ransack, um nach f.search_field zu suchen: user_id_eq (oder was auch immer), um alle Auftragspositionen zu erhalten, die zu user_id = 1 gehören, sowie alle Auftragspositionen, die von user_id = 2 und plus user_id = 3 gehören?
Vielen Dank für Ihre Unterstützung.