Download the PHP package oxyaction/yii2-polymorphic-relation-behavior without Composer

On this page you can find all versions of the php package oxyaction/yii2-polymorphic-relation-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-polymorphic-relation-behavior

Yii2 RelatedPolymorphic Behavior

This behavior helps to establish polymorphic behaviors easily. Forget about endless dictionary tables in your storage.


Build Status Latest Stable Version Latest Unstable Version License

Problem

Often you have some entity related to multiple entities in your system. For example Comment entity can belong to both Article, Photo, Post etc. You can create a comment table for each of this entities (ArticleComment, PhotoComment, PostComment), but this solution is not so good and not DRY at all.

The best solution will be creating the single Comment entity table and establishing polymorphic relations. The comment table is required to have type column that will indicate to which entity type comment belongs and external_id column that will be used as foreign key column.

Then you can query relations as always

Options

Has many

Short:

Same as

Many to many

Often we need to establish polymorphic relation with many to many. in this case type and external_id columns will be in junction table.

All available options:

Some options can be set on per behavior or per relation level. For example polymorphicType from example above is set on behavior level, while typeColumnName on relation level. In case if you set option on behavior level you won't need to duplicate it for multiple relations while relation option will take precedence.

Option Description Required Default Level Type
type RelatedPolymorphicBehavior::MANY_MANY or RelatedPolymorphicBehavior::HAS_MANY Yes relation
class related model class name Yes relation
polymorphicType type of the polymorphic entity Yes behavior, relation
viaTable junction table name Yes relation MANY MANY
pkColumnName source model pk column name fetched from schema behavior, relation
foreignKeyColumnName foreign key external_id behavior, relation
typeColumnName column name for type of polymorphic model type behavior, relation
deleteRelated delete related values, after removing primary model false relation HAS MANY
otherKeyColumnName related model's foreign key column name in junction table fetched from schema relation MANY MANY
relatedPkColumnName related model's pk column name fetched from schema relation MANY MANY

Final example

This will assume that taggable_tag, image and comment tables have some_external_id and entity_type columns, for Article entity it will be filled with article value and Article primary key column name is ID.

Warning

Since external_id of the polymorphic target entity links to multiple entities, you can not use foreign key constraints and need to check data consistency on application level.


All versions of yii2-polymorphic-relation-behavior with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package oxyaction/yii2-polymorphic-relation-behavior contains the following files

Loading the files please wait ....