On Tue, Mar 5, 2013 at 3:48 PM, Michael Graff <[email protected]> wrote: > Howdy. > > I have these models: > > User, field "mundane_name" > user has_one :instructor_profile (may or may not exist) > > instructor_profile, field "sca_name" > belongs_to :user > > I would like to craft a search on these fields, which is effectively this, > but in one go: > > matching_users = User.where("mundane_name ILIKE ?", "%#{target}%") > matching_profiles = InstructorProfile.where("sca_name ILIKE ?", > "%#{target}%").map(&:user) > > (matching_users + matching_profiles).uniq > > However, I'm having problems formulating the query. Not all users have a > profile, so some of the joins techniques would not work as they would only > search a user if a profile existed as well. > > Any suggestions?
Stupid question of the evening: Do users that don't have profiles have sca_names? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

