Jahnavi

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Rails Admin with has_many association

Hi all,

We are using rails_admin for manging our data on admin side.

We are facing an issue with has_many association ,** its executing the query to fetch the details and along with it also executing one more query to get total count from that table.
i.e. see below queries.
SELECT * FROM table_nameWHERE condition
SELECT COUNT() FROM table_nameWHERE condition*

Here;s sample model.

has_many :users, :foreign_key => :user_id, :primary_key => :id

rails_admin do
edit do
field :users do
label "Linked Users"
inline_add false
end
end
end

Can you please help me how can we avoid execution of second query.

Thanks in advance

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2023 GoRails, LLC. All rights reserved.