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

Ability to exclude specific columns #226

Open
finiteinfinity opened this issue Nov 26, 2021 · 0 comments
Open

Ability to exclude specific columns #226

finiteinfinity opened this issue Nov 26, 2021 · 0 comments

Comments

@finiteinfinity
Copy link
Contributor

finiteinfinity commented Nov 26, 2021

There doesn't seem to be a way of excluding column by name currently. I've come across a few situations where this would be a desired behaviour, e.g. when using generated columns in MySQL. Take the following table defintion:

CREATE TABLE `order_lines` (
    `quantity` INT NOT NULL,
    `price` DOUBLE NOT NULL,
    `total` DOUBLE AS (`price` * `quantity`) STORED
);

currently, the library generates models with the total property and allow it to be overridden. However, mysql actually prevents generated columns from being updated:

If a generated column is updated explicitly, the only permitted value is DEFAULT.

This ends up in an exception being thrown if the property is ever overridden.

My suggestion is to add the excludes key in models.php, which accepts either fully qualified table names or patterns (to match the behaviour of except):

<?php

return [

    '*' => [
        'excludes' => [
            'order_lines.total',
            '*generated'
        ]
    ]

which would exclude the total property in the OrderLine model and all properties in all models ending with generated

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

No branches or pull requests

1 participant