Skip to content

Conversation

shmax
Copy link
Contributor

@shmax shmax commented Sep 4, 2023

Reorganizing Model::$belongs_to and Model::$has_one from this:

 public static $has_many = [
        ['payments'],
        ['people',
            'through'    => 'payments',
            'select'     => 'people.*, payments.amount',
            'conditions' => 'payments.amount < 200']];

to this:

public static array $has_many = [
        'payments' => true,
        'people' => [
            'through'    => 'payments',
            'select'     => 'people.*, payments.amount',
            'conditions' => 'payments.amount < 200'
        ]
    ];

This makes static checking on the options possible, and easier to read IMO.

TODO: a lot of the tests rely on static members like Model::$belongs_to, Model::$has_one, and so on. Some of the tests would try to cache and restore the state of these, others would append, still others would reset, which can lead to chaos. I think what we need to do is figure out how to do some kind of before_test sort of thing where we always blank those out, or maybe do some kind of mocking, or something.

@shmax shmax changed the title remove static checking of conditions Reorganize Model::$belongs_to, Model::$has_one Sep 4, 2023
@shmax shmax merged commit 3382af3 into master Sep 4, 2023
@shmax shmax deleted the clean-up-relationships branch September 4, 2023 03:15
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

Successfully merging this pull request may close these issues.

1 participant