简体   繁体   中英

Ruby on rails rails_admin with has_many association

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. ie see below queries.

SELECT * FROM table_name WHERE condition

SELECT COUNT(*) FROM table_name WHERE 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

did not get you, you want to remove field :users from edit form? if yes, you add

rails_admin do
  edit do
    exclude_fields :users
  end
end

otherwise, you just want to disable add user from the form, the rails_admin still need to run those sql to fill users combobox on your form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM