In a custom plugin is it possible to have a element type with a belongs to relationship to a user, as you can only define half of the relationship (without somehow modifying the userRecord).

What would be the best practices to get something like this working?

1 Answer 1


Assuming your plugin is going to be the only thing referencing this Active Record relationship, your plugin could have its own MyUserRecord that extends Craft's UserRecord and does something like:

public function defineRelations()
    $relations = parent::defineRelations();

    $relations['myUser'] = array(static::BELONGS_TO, 'MyUserRecord', 'id', 'required' => true, 'onDelete' => static::CASCADE);

    return $relations;

And you would just utilize MyUserRecord instead of Craft's UserRecord in your plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.