GithubHelp home page GithubHelp logo

yii2tech / ar-role Goto Github PK

View Code? Open in Web Editor NEW
36.0 36.0 8.0 31 KB

ActiveRecord behavior, which provides relation roles (table inheritance)

License: Other

PHP 100.00%
activerecord role roles yii yii2 yii2-extension

ar-role's People

Contributors

klimov-paul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ar-role's Issues

cascade of models

Is it possible to create cascade of models which inherite each others like Human->personal->teacher in three tables human, personal, teacher?

different instances

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.

Create new Student in Master role inheritance

$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; 
}

Issue with yii 2.0.14

Enh #13618 in yii2 2.0.14 breaks ar-role behavior

For example, in AfterInsert event I cannot reach role attributes anymore.

where() support?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.