Giter Club home page Giter Club logo

ar-linkmany's Issues

Multiple saving many records

I tried to add this behavior for link between tables group and category using pivot table category_group that have columns group_id and category_id.

When I added behavior and set up "virtual property" groupsIds, I tried to execute request with adding one category with three records from group to be related with: groupsIds => [1,2,3]
As expected from link method, I got three MySQL queries:

INSERT INTO `category_group` (`category_id`, `group_id`) VALUES (6, 1);
INSERT INTO `category_group` (`category_id`, `group_id`) VALUES (6, 2);
INSERT INTO `category_group` (`category_id`, `group_id`) VALUES (6, 3);

So I think it's better to use one query:

INSERT INTO `category_group` (`category_id`, `group_id`) VALUES (6, 1), (6, 2), (6, 3);

What do you think about enhancement? Is it needed or no?

FR: extra columns

Could extraColumns be specified in the reference attribute?

$model->reference = [1 => ['extra' => 'value'], 2, 3 => ['extra' => 'other']];

This would be a good way to update any extra columns too where the keys stay the same.

Deleting related records

When I tried to use delete method for the model with defined behavior, it's relations didn't delete. Maybe it could be useful to add EVENT_AFTER_DELETE handler and unlink all related records.

relationReferenceAttribute as Unsafe attrubutes

Is there a way to implement the feature? I'd like to set some attrubutes depends on user group. For example, only Admin can change groupIds.

I tried
public function rules() { return [ [['!groupIds'], 'safe'], ]; }
controller:
$post = Yii::$app->request->post(); if (Yii::$app->user->hasRole('admin') && isset($post[$model->formName()]['groupIds'])) { $model->groupIds = $post[$model->formName()]['groupIds']; }
but it has no effect.

After
$model->load($post)
anyone can change the attribute

Pass $model in extraColumns anonymous function

I need to get id of related model to set the value of my ExtraColumn.

Like this:

'extraColumns' => [
    'option_id' => function($model) {
        return isset($this->optionsIds[$model->id]) ? $this->optionsIds[$model->id] : null;
    }
]

I will create pull request for it.

relationReferenceAttribute and dirtyAttributes

Hi,
If the contents of the relationReferenceAttribute array changes, then this attribute does not fit in dirtyAttributes, so they do not work out behaviors like TimestampBehavior, BlameableBehavior and others.
(\yii\behaviors\AttributeBehavior::evaluateAttributes)
How to be in this situation?

Question for Events and blameable columns

Hi

is there a way to trigger Events on each link / unlink the models?

e.g. if i use the behavior to save the relation between a submission and a reviewer.

So after an allocation of an reviewer an email should be sent out to this newly linked reviewer.
Also some email should be sent on unlink.

Currently I only see the possibility of saving the value before and after Update and get the newly linked and relations to remove myself and use this information to create the emails.

But maybe you got some better suggestion?

Another question is there a better way to have blameable columns filled with the correct information?
Currently i fill those fields like following:

'extraColumns'               => [
    'reviewer_type' => self::REVIEW_TYPE_INVIVIDUAL,
    'created_at'    => function () {
        return Carbon::now('UTC')->toDateTimeString();
    },
    'updated_at'    => function () {
        return Carbon::now('UTC')->toDateTimeString();
    },
    'created_by' => function () {
        return Yii::$app->user->id;
    },
    'updated_by' => function () {
        return Yii::$app->user->id;
    },
],

best regards

Sorted many-to-many links

I have many-to-many links. I want to sort them. Can use extra field for this? I write extra field when creating a connection. But how can update extra field for exist links? Please any example.

links TABLE actor_movie (
actor_id int
movie_id int
movie_ord int
)

Property to honor "delete" flag for unlink

Hi,

Love this behavior !

Would it be possible to add a property to set the delete flag when calling unlink ?
When used on a many-to-many relation with a pivot table, I need to delete entries, not to set it to null.

Thanks

Невозможно провалидировать атрибут через EachValidator

@klimov-paul Павел, добрый день!

$value = [$value];

В данной строке бехейвера принудительное привидение аттрибута к массиву из-за этого невозможно провалидировать массив данных( массив связывания таблиц - "groupIds") через EachValildator так, как внутри валидатора в цикле аттрибуту (groupIds) присваивается значение каждого эллемента массива.

https://github.com/yiisoft/yii2/blob/dd3e5ec1e27f9fc475d41f6aeebdd5f565d813d4/framework/validators/EachValidator.php#L143

Saving form without related Ids

Steps to reproduce the problem:

  1. Init LinkManyBehavior:
'linkServicesBehavior' => [
  'class' => LinkManyBehavior::className(),
  'relation' => 'salons',
  'relationReferenceAttribute' => 'salonsIds',
],
  1. Adding 'salonIds' as safe attribute
  2. Do not add salonIds field into _form.php

The problem is:
Invalid argument supplied for foreach() in LinkManyBehavior.php:245

Need to check if $this->owner->{$this->relation} isset.

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.