Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort_link on polymorphic association but with multiple model #782

Closed
dipaktc opened this issue Apr 12, 2017 · 3 comments
Closed

sort_link on polymorphic association but with multiple model #782

dipaktc opened this issue Apr 12, 2017 · 3 comments

Comments

@dipaktc
Copy link

dipaktc commented Apr 12, 2017

I have following polymorphic relationship

class Offer < ApplicationRecord
belongs_to :offerable, polymorphic: true
end

class Company < ApplicationRecord
has_many :offers, as: :offerable, dependent: :destroy
end

class Location < ApplicationRecord
has_many :offers, as: :offerable, dependent: :destroy
end

Now Offers are offerable with either Company or Location.

In the both tables (Company, Location), name field is there in the database.

= sort_link(query, :offerable_of_Company_type_name) do
%span{ class: ["btn btn-outline-success btn-sm", ('active' if params[:name])] } Name

Above code is working but I want to search with Company name as well as Location name so I will try below

= sort_link(query, :offerable_of_Company_type_name_or_offerable_of_Location_type_name_cont, 'name') do
%span{ class: ["btn btn-outline-success btn-sm", ('active' if params[:name])] } Name

But Now, above code is not working. So how can I sort with two fields for offerable. I want to sort with Company name as well as Location name.

@scarroll32
Copy link
Member

This issue appears more to be a HOW-TO issue rather than a bug in Ransack. We are in the process of cleaning up the Ransack gem and repo. If this issue is still relevant could you please ask it on StackOverflow?

If you think it is an issue with Ransack, please provide a repo with the issue and / or a pull request with failing tests. If you don't know how to do this, indicate it in the issue and we will look into it eventually.

Thank you

https://github.com/activerecord-hackery/ransack/blob/master/CONTRIBUTING.md

#794

@muhammad-tayyab-ashraf
Copy link

@dipaktc I am also facing that same issue. Any solution for this issue?

@foohooboo
Copy link

I'm running into the same blocker, but with the added complexity of having different attribute names in the different associations. I have a Notification with a polymorphic 'originator' that can be a Person, Group, or Channel. Person has 'last_name', while Group and Channel have 'name'.

I can sort via both of these sort_links:
sort_link(@page.query, "originator_of_Person_type_last_name, "Originator Name")
sort_link(@page.query, "originator_of_Group_type_name, "Originator Name")

However, I cannot sort by:
sort_link(@page.query, "originator_of_Person_type_last_name_or_originator_of_Group_type_name, "Originator Name")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants