yii2tech / ar-role Goto Github PK
View Code? Open in Web Editor NEWActiveRecord behavior, which provides relation roles (table inheritance)
License: Other
ActiveRecord behavior, which provides relation roles (table inheritance)
License: Other
RoleBehavior::$roleAttributes
should be applied before model validation, supporting of the complex validation, e.g. unique record name per role.
Is it possible to create cascade of models which inherite each others like Human->personal->teacher in three tables human, personal, teacher?
Hi. Just a question.
Is there a way to get array of Student and Instructor instances after $humans = Human::find()->all();
I feel need to use in the Human model something like
public static function instantiate($row) {
switch($row['role']) {
case 'student': {
...
return new Student($row);
}
....
}
}
but the method generates extra queries. Don't understand how to do it clear and beatiful.
$model = new Student();
$model->name = 'John Doe';
$model->address = 'Wall Street, 12';
$model->studyGroupId = 14;
$model->save(); // insert one record to the 'Human' table and one record - to the 'Student' table
this doesn't work in Master role inheritance... it doesn't create master record and throws \yii\db\Exception on Student's humanId column (null value in column "humanId" violates not-null constraint)
Is it right?
PS:
in RoleBehavior.php #286
if (!$this->isOwnerSlave) { // <-- this skips master model insert
if (!empty($this->roleAttributes)) {
foreach ($this->roleAttributes as $name => $value) {
$this->owner->$name = $value;
}
}
return;
}
you missed the function in "public static find()".
In case of usage 'slave' role inheritance, role relation model is always fetched and saved even if it is not needed.
For example: in case of update the existing record or if link to role entity is explicitly set.
Enh #13618 in yii2 2.0.14 breaks ar-role behavior
For example, in AfterInsert event I cannot reach role attributes anymore.
Hi,
I'm sorry I'm posting a question here, because I don't know where I should ask this.
I'm using this extension, and reading and updating data works fine. But when I want to use the where function as in Models::find()->where()->all()
to filter the column in the related table, I get an error because the column is not in the main table.
Currently I only get it working using something like this:
->with([
'relation_name' => function($query){
$query->andWhere(['column_in_related_table' => 'value']);
}
])
Is there any way of using it just like Models::find()->where(['column_in_related_table' => 'value']))->all()
?
If this is supported, where I might be wrong?
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.