I already answered my own question but I wouldn't mind accepting any other answer that is really better than my approach (do mention how it is better). Please contribute.
I had a situation where in my User Model
, I had first_name, middle_name, last_name
as 3 separate fields and only first_name
being validated against empty/NULL
, i.e., the other 2 can be empty/NULL/whitespace(didn't want to annoy the users with unreasonable validations, I personally know people who don't have/use their last names for some crazy reasons).
With such structure, it is reasonable to expect the displayfield
as a compound of all these 3 columns, keeping in mind that the other 2 might be ""/NULL/white-space (since they are all VARCHAR columns). Also, my DB table has columns like created_by
, modified_by
, approved_by
, assigned_to
... (heck lot of other aliases for this model, but all of them well related following the "CakePHP convention").
I read the official documentation and several posts here on SO like this one. But none of them offers a solution or sample for this kind of a situation. Perhaps, my DB structure is too unconventional or I'd say "unorthodox" ;) (well, the official documentation does answer on multiple model aliases, which I missed several times, which motivated me to post this question and answer it here on SO).
So, the question is how to correctly address such model relationship and structure?