0

I have general field search in ActiveScaffold working. I'm not sure how to do this more complex searching.

I have two tables, Account and User, and I want to search emails and get back a list of matching accounts. The email field is in User, and Account has_many :users.

I am having trouble thinking through how the query should happen. Ideally I'd like to do something like this:

Account.where(email: 'search_term').all

or

User.where(email: 'search_term').includes(:account).all

John
  • 485
  • 2
  • 5
  • 15

1 Answers1

0

If you want to search for data from one table and return results from(including) another, just add those foreign columns as virtual columns:

in User controller:

active_scaffold :user do |conf|
conf.search.columns << :email
conf.list.columns << :account
#...
end

That's it, no queries :)

if account column results appears code like <#23423.. it's because Active Scaffold can't tell how to describe that class records, so you tell it how you want in the model:

class Account << ActiveRecord::Base
....
def to_label
 "cod: #{account_number}"
end 
naaano
  • 21
  • 5