Skip to content

Virtual fields aren't cast #117

@Blue3957

Description

@Blue3957

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions