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

Maybe hasOne->addField() can inherit field defaults from related model? #185

Closed
DarkSide666 opened this issue Oct 7, 2016 · 7 comments
Closed
Assignees
Labels
hangout agenda 🔈 Will discuss on next hangout

Comments

@DarkSide666
Copy link
Member

DarkSide666 commented Oct 7, 2016

If somehow we could get field properties from related model, then we can put them here: https://github.com/atk4/data/blob/develop/src/Reference_SQL_One.php#L46

For example,

class Model_RequestField extends Model
{
    public $table = 'request_field';

    public function init()
    {
        parent::init();

        $this->addField('type', [
            'type' => 'string',
            'mandatory' => true,
            'enum' => array_keys($v = [
                'moment'    => 'Moment',
                'datetime'  => 'DateTime',
                'int'       => 'Integer',
            ]),
            'ui' => ['valueList' => $v],
        ]);

        // hasMany
        $this->hasMany('Field');
    }
}

class Model_Field extends Model
{
    public $table = 'field';

    public function init()
    {
        parent::init();

        $f = $this->hasOne('request_field_id', ['RequestField', 'mandatory' => true]);
        $f->addField([
            'type',
            // these properties below would be nice to inherit from related model automatically by default
            'type' => 'string',
            'mandatory' => true,
            'enum' => array_keys($v = [
                'moment'    => 'Moment',
                'datetime'  => 'DateTime',
                'int'       => 'Integer',
            ]),
            'ui' => ['valueList' => $v],
        ]);
@romaninsh
Copy link
Member

I tried this with type but problem is that this makes it super slow. Maybe we should define inheritance explicitly.

@romaninsh
Copy link
Member

Has one is readonly but we need this for model joining.

@romaninsh
Copy link
Member

I think this feature would be an overkill for basic functionality.

@DarkSide666
Copy link
Member Author

Yeah probably, but still nice to have at some point :)

@PhilippGrashoff
Copy link
Contributor

Maybe 447 implemented this?

@PhilippGrashoff
Copy link
Contributor

#447

@mvorisek
Copy link
Member

partly fixed in #880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hangout agenda 🔈 Will discuss on next hangout
Development

No branches or pull requests

5 participants