Relevance Model



( ZN >= 5.3.5 )

It is a mode designed to merge multiple tables. Establish relationships between specific tables. With this relationship, common data collection, updating, deletion, etc. are common to the related tables. It is a modeled version of a nested join process.

 

 

# Section Headings


# Creating Relevance Model File

# Different Relationship Selection
# Multiple Relationship
# Default Table
# Default Select Expression

# Methods Relevance Model

 

 

# Creating Relevance Model File


To make a model relevance , the RelevanceModel file needs to be extended to that class . After this enlargement, it is const relevancenecessary to indicate the tables to be related to the constancy.

Rule first_table.column: second_table.column [ => join_type = 'inner' ]
File: Models / BlogCat.php
<?php

class InternalBlogCat extends RelevanceModel
{
    const relevance = 
    [
        'blog.category_id:category.id'
    ];
}

In the above definition, we have established an inner level relationship between the Blog and Category tables. It is possible if you define the relationship outside of Inner.

Different Relationship Selection

By default, if no relationship type is specified inner joinacceptable. To change thisrelevance Add the join method as the value of the join statement that is written to the constant.

File: Models / BlogCat.php
<?php

class InternalBlogCat extends RelevanceModel
{
    const relevance = 
    [
        'blog.category_id:category.id' => 'left'
    ];
}
Multiple Relationship

You can relate the number of tables you want. All you have to do is add the other relationship expressions you need.

File: Models / BlogCat.php
<?php

class InternalBlogCat extends RelevanceModel
{
    const relevance = 
    [
        'blog.category_id:category.id'     => 'left',
        'category.id:comments.category_id' => 'right'
    ];
}
Default Table

SELECT cols ... FROM table in statement tableThe value is the first table name added to the relevance constant . So this is the table according to the example above . This information will help you make the relationship between the tables more accurate.blog

Default Select Statement

if select ()By default, all tables table_columnare imported in the form of columns . Thus, even if you do not specify any select parameters, you will catch all the columns of the associated table without any conflicts.

 

 

# Methods Relevance Model


When you extend the RelevanceModel, your model file gets some skills. AllSELECT and output methods you can check your data specifically with the following methods.

Object rowtablecolumn ()
Bool update ()
Bool delete ()
Bool repair ()
Bool optimize()
Bool backup ()
Bool status ()
Bool drop ()
Bool truncate ()

 

 

# Row / Result ( ZN >= 5.3.5 )


The results of your model file row () , result (), or other output methods.

$row = BlogCat::row();
$result = BlogCat::result();
Other Output Methods

You can also use other output methods of the database other than Row and Result.

$resultArray = BlogCat::resultArray();
Custom Row Usage

When you register a single line, you can only use the condition together with 1 where the condition is invalid.

rule1 rowTabloColumn ( $ value , [ $ operator = '=' ])
Kural2 rowDatabaseTabloColumn ( $ value , [ $ operator = '=' ])
Parameters
String $ Value Column value.
String $ Operator Comparison operator.
return Object
uses

For example , let's take the column with id column 1 of the blog table .

$row = BlogCat::rowBlogId(1);

Let's take the non- name column 'ZN' of the category table .

$row = BlogCat::rowCategoryName('ZN', '!=');

 

 

# Other Selection Methods


Database GroupBy (), orderby (), limit() You can use all other methods like.

BlogCat::orderBy('category.id', 'asc')->result();

 

 

# Update ( ZN >= 5.3.5 )


Used to update the data associated with the consolidated table.

BlogCat::where('blog.id', 5)->update(
[
    'blog.name' => 'New Blog Name', 'category.name' => 'New Category Name'
]);
Use Custom Update

You can use the conditional update method.

rule1 updateTabloColumn ( $ data , $ value , [ $ operator = '=' ])
Kural2 updateDatabaseTabloColumn ( $ data , $ value , [ $ operator = '=' ])
BlogCat::updateBlogId(
[
    'blog.name' => 'New Blog Name', 'category.name' => 'New Category Name'
], 5);

 

 

# Delete ( ZN> = 5.3.5 )


Used to delete data associated with a consolidated table.

BlogCat::where('blog.id', 5)->delete();
Using Private Delete

You can use the conditional delete method.

rule1 deleteTabloColumn ( $ value , [ $ operator = '=' ])
Kural2 deleteDatabaseTabloColumn ( $ value , [ $ operator = '=' ])
BlogCat::deleteBlogId(5);

 

 

# Other Methods


The use of other methods is the same.

Parameters
void
return Mixed
uses
BlogCat::repair();
BlogCat::optimize();
BlogCat::backup();
BlogCat::status();
BlogCat::drop();
BlogCat::truncate();