Hi,

As models get complicated, I have been thinking at some point that
defining association by default in the model gets little to no use. I
understand that the auto-magic queries are what made the association
important but the sheer amount of queries just irritates me at times.
I end up thinking why wouldn't I just use bindModel in my self defined
Model->getSomeData or Model->getOtherData method so only the required
data and tables get queried. Now, I understand that with these, the
rapid development gets not so rapid. For example of a very simple job
application system, this is a model defined according to the actual
relationship:

[Application]
belongsTo
  - Job
  - User

[Job]
belongsTo
  - Department
hasMany
  - Application

[Department]
hasMany
  - Job

[User]
hasOne
  - Profile
hasMany
  - Application
  - Document

[Document]
belongsTo
  - User

[Profile]
belongsTo
  - User

To get a show a list of applications with the relevant profile, I did
a Application->findAll() with recursive level of 2. The results goes
like:

array(
    [0] => array(
        [Application] => array(
            ...data...
        )

        [User] => array(
            ...data...

            [Profile] => array(
               ...data...
            )

            [Application] => array(
                [0] => array(
                    ...data...
                )

                [1] => array(
                    ...data...
                )
            )

            [Document] => array(
                [0] => array(
                    ...data...
                )

                [1] => array(
                    ...data...
                )
            )
        )

        [Job] => array(
            ...data...

            [Department] => array(
               ...data...
            )

            [Application] => array(
                [0] => array(
                    ...data...
                )

                [1] => array(
                    ...data...
                )
            )
        )
    )

    [1] => array(
        ... more data here ...
    )
)

Clearly, in such cases when the models are mostly inter-linked, the
amount of duplicated information gets scary. I was just trying to get
Profile information of the user of each Application to show up but so
much more other information gets queried. The most scary one being Job
hasMany Application. See how all the applications of the Job applied
will get queried each time for each Application listed. The easy way
out is to change or remove some association or even add a Application
belongsTo Profile association but that will mean the relationship is
somewhat  awkard since Application really belongsTo a User whom hasOne
Profile.

Alright, in case my post gets really lengthy (it already is... :p), I
hope you guys get the point. So what will you do in this case or
rather in general, will you rather not define any association to begin
with? Or maybe it will be nice to have a way to specify like i just
want Application.User.Profile in my recursive call so I can actually
pass that into my findAll() call and magic happens? Despite not
knowing CakePHP very well, please let me know if there is anything I
can help with.

Will be nice to hear from you guys!

Cheers,
Derick Ng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to