Skip to content
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

Virtual fields aren't cast #117

Open
Blue3957 opened this issue Aug 5, 2022 · 0 comments
Open

Virtual fields aren't cast #117

Blue3957 opened this issue Aug 5, 2022 · 0 comments

Comments

@Blue3957
Copy link

Blue3957 commented Aug 5, 2022

I come forward with an issue I mentioned on Slack a couple of days ago.

When setting up relations through virtual fields, using the function cast() leaves them as they are and you end up with something that looks like this:

^ array:6 [▼
  "one_property" => "lorem"
  "virtual_two" => Models\Two {#17 ▶}
  "virtual_three" => DB\CortexCollection {[#26 ▶}
  "two" => array:3 [▶]
  "three" => array:1 [▶]
  "_id" => 1
]

If your virtual function returns an instance of Cortex or CortexCollection, I think it would be desirable to see them get cast when casting the model, just like regular relations are.

An example of a use case would be a virtual field for unpaid invoices from a client. This cannot be setup in the fieldConf as you don't want to get all invoices regardless of status, only the unpaid ones.

Here's a small repo (I made it as concise as possible) that reproduces the error, should you need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant