I have a many to many relastionship through join table :
team.rb
has_many :partners_teams
has_many :partners, through: :partners_teams
partner.rb
has_many :partners_teams
has_many :teams, through: :partners_teams
partners_team.rb
belongs_to :team
belongs_to :partner
self.primary_key = :partner_id
include RankedModel
ranks :row_order, with_same: :team_id
default_scope { order(row_order: :asc) }
I set an additional row "row_order
" integer in the join table teams_partners
Partner is a nested resource of Team
How can I address the row_order column when I request the partners from a designed card, which happens in partners#index
and cards#show
Currently, I do (it works correctly) :
Partners#index :
def index
@card = Card.find(params[:id])
@partners = @team.partners.all
end
Teams#show
def show
@partners = @team.partners.all
end
I tried several things with joins and include but with no success. It's still a bit complicated to my level.
Moreover, I use Harvest ranked-model gem to sort my partners. It seems to work well except the initial order (problem described above). Thing is ranked-model use the .rank() method to order things. Ex: Partners.rank(:row_order)
. I'm not sure if that's a thing to take into account, I mean I can use an Partners.order(row_order: :desc)
, but maybe that'll have an impact for the following sorting.
Any help appreciated, really.
Thank you a lot.