Re: Associations - Better solution?

Frederick Cheung
2009-07-12T20:35:46Z

On Jul 12, 3:43 pm, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org>
wrote:
> When a user is retrieved for access and functionality validations, I
> re-retrieve the user through the specific user class as in:
>   user = User.find(...)
>   # The user is found and passes validations.
>   # Now I re-retrieve it through the specific user class based in the
> category value.
>   user = user.category.capitalize.constantize.find(user.id) if user
>
> From that moment on I have the user retrieved through its correct type
> and my associations work wonderfully.

If you use single table inheritance then User.find(...) would
automatically return an instance of Tenant, Auditor or Admin as
appropriate and you wouldn''t need to refetch it.

Fred

>
> Is there a better way of making this work?
>
> Thanks.
>
> Pepe