On Aug 10, 7:54 pm, "Leonel *.*" <li...@ruby-forum.com> wrote:
> ---------------------------------------------------------------
>
> You can easily see that if the database grows, looking for ALL account
> owners in the database can take up a lot of resources. Can you suggest
> an easier way to find the account owner company id when being logged in
> as a customer?
>

Your data structure feels a little weird to me - Presumably accounts
have multiple companies. So does someone with role_id == 1 own all the
companies in the account that the company_id points to? It feels a
little lopsided to have this one privileged company. I think
personally I would give account an owner_id attribute.

Anyway, assuming that users will grow rapidly but that an account will
only ever have a manageable number of companies in it, something like

all_companies_in_account = current_user.company.account.companies
owner = User.find_by_role_id_and_company_id(1,
all_companies_in_account)

would find you the owner.

Fred

> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to