New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing virtual fields and getters on associated entities #8246
Comments
Ok, looks like what happened is that 6c5c6cb started caching the accessor methods. However, it builds the cache using the underscored property names (Since that is the cakephp convention), using |
I can take a look. |
This fixes a regression introduced in while optimizing entity accessors. Refs #8246
Pull request open now. |
Still having this issue as of 3.2.3 with the same code. The schema I'm forced to use isn't camel cased, but title cased. i.e. ClientId, PatientId, FirstName, etc... I'm sorry I had it listed as listIdName, camel cased, earlier. I'm looking to output using the same format ($patient->client->ListIdName) but I'll change things over to @dakota's solution for now. Thanks! |
I'm working on 3.3.8 and having a similar issue. Not sure when it started becoming a problem, but virtual fields. Any virtual fields, actually. Associated Models or not. |
@holisticnetworking So no virtual fields are working? |
Yes, sorry. I should have been more specific. Here is one virtual field declaration for a Model called "Client" protected function _getFullName() {
return trim( $this->_properties['first_name'] ) . ' ' .
trim( $this->_properties['last_name'] );
} However, when I access a page - either for this Model or one of it's associated Models - the field does not show up. For example, this json string:
And so on. I can't seem to backtrack it - I've been working in areas for which virtual fields are not needed for a few weeks. But disabling any but the default plugins does not seem to resolve the issue, either. The Clients query above includes no special custom queries or other razmatazz. |
Ok. Is protected $_virtual = ['full_name']; |
Ok.. Is this a new requirement? Because I swear they were working a few months ago without a $_virtual definition? Probably not. Either way, thanks for the help @markstory and sorry about the issue report! |
|
VirtualFields have always required to be listed in the |
In array conversions? So, not in objects created by the query builder? On Tue, Nov 22, 2016, 2:55 PM Mark Story notifications@github.com wrote:
|
Sorry, I was unclear. By 'Array Conversions' I meant in the results of I'll update the documentation as you're right that requirement is not clear. |
I found the existing section in the documentation. What would make this section easier to find? Perhaps a link in the Virtual Fields section? |
Using both fields and properties can be confusing. Refs cakephp/cakephp#8246
Using both fields and properties can be confusing. Refs cakephp/cakephp#8246
I think that simply adding a highlighted callout here, like you do for other docs (class="admonition note") that says "Note: special rules apply for array and JSON conversions" with a jump link to the relevant text below is sufficient. May I ask why this distinction exists? To me, unless you specifically protect a field with $_hidden, the data is what the data is. Regardless of what's done with it? |
@holisticnetworking Knowing all the virtual properties on an entity would require non-free reflection if we didn't have the explicit list, as virtual fields aren't defined anywhere other than by implementing methods via a naming convention. |
Thanks for the explanation. |
After upgrading my Cake 3.1.x project to 3.2.x, I can no longer get values besides (null) for virtual properties made through getter functions on my find() associated entities.
Here is a simple example of my problem using my
Patients
model finding theirClient
association.Controller code:
Here is the virtual property I have set in my
Client
entity:This is returning (null) for
$patient->client->listIdName
which I can't seem to figure out.I have tried changing the getter functions to public scope, which does not help. I've also tried using the paginate() method after adding the contain() to the original query as opposed to in
$this->paginate[]
. The result keeps coming back null.Here is the relevant output of
pr($patients->first())
on my query before pagination:As you can see, the virtual fields are not there. These worked in CakePHP 3.1.10 but are not working in 3.2.1 or 3.2.2 that was just released.
I didn't see anything in the changelog about this functionality changing so I'm hoping this is just a bug and not something I'm doing wrong. Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: