On Sep 21, 12:25 pm, Jason <[EMAIL PROTECTED]> wrote:
> I have an interesting issue with my model relationships that I'm
> attempting to figure out how to take care of in the most elegant
> fashion.
>
> Basically, I have a User model, a Profile model, and then multiple
> extended Profile models (ex: AdminProfile, etc.) which have
> information specific to that type of user.
>
> The user table has a "type" column which is an enum and designates
> what type of user I have.
>
> My relationships are setup so that
>
> User HAS ONE Profile
> Profile BLEONGS TO User
> AdminProfile BELONGS TO Profile
> XProfile BELONGS TO Profile
> YProfile BELONGS TO Profile
These different types of profile are in different tables, or in the
same table with a type field? What is the reason for the profile types
being associated with Profile instead of the user?
>
> How can I get this extended profile information linked to my User or
> Profile models on the fly? I know about bindModel and unbindModel, but
> I'm not sure where best to use it.
>
> One thing I tried was modifying the afterFind() callback for User and
> Profile to grab the user type and do an extra query for the extended
> information.
Have a look at the polymorphic manner in which Uploads are associated
with other models in the system (via afterFind) with the upload
behavior I recently wrote about
http://www.ad7six.com/MiBlog/GenericFileUploadBehavior (http://
cakeforge.org/frs/?group_id=152&release_id=324)
> This feels dirty, however. It also breaks scaffolding
> which is kind of annoying because I'm at the beginning stages of this
> project.
If you are using scaffolding you'd be best off leaving it as User
hasOne (List Of Profiles) or User HasMany (generic NoneTyped Profile)
IMO. You may find that even after your scaffolding phase you want to
leave it as User hasOne (List Of Profiles) so that there are no extra
queries just redundant joins. You have to choose between the two since
you don't know which profile to retrieve until after you've read the
User data.
hth,
AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---