On 5 March 2013 21:48, 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

Are you sure you want separate models for these?  I am always
suspicious when I see has_one.  Often it is much easier just to
combine the tables into one and leave irrelevant fields empty.  If
"instructor" is a role that certain players have then it might also be
worth looking at the cancan gem.

Colin

>
> 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?
>
> --
> 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.
>
>

-- 
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.


Reply via email to