The correlation model

Source: Internet
Author: User

Original: 5-relevance model

1, SectionModel.class.php

To inherit Relationmodel, the mapping model and class name write correspond to the data table and the action class

1<?PHP2     classSectionmodelextendsrelationmodel{3          Public $_link=Array(4' Category ' =Array(5' Mapping_type ' =>has_many,//Association Relationship 1:n6' Class_name ' = ' Category ',//corresponding class name7' Foreign_key ' = ' SectionID ',//foreign key, category table field8' Mapping_name ' = ' category ',//Mapping Model9' Mapping_order ' = ' SectionID desc ',//Map SortTen), One' Article ' =Array( A' Mapping_type ' =>has_many, -' class_name ' = ' article ', -' Foreign_key ' = ' SectionID ', the' Mapping_name ' = ' article ', -              -), -         ); +         

2, SectionAction.class.php

Turn on association relation (True)

<?PHPclassSectionactionextendscommonaction{ Public functionindex () {$sec=NewSectionmodel ();//Relation (TRUE) associates all associated data//-----queries that hold the user model definition//dump ($sec->relation (True)->find (3));/*----Create data 2.INSERT into ' joys_section ' (' title ') VALUES (' Custom units ') [runtime:0.001198s]3.show COLUMNS FR OM ' joys_category ' [runtime:0.005667s]4.insert into ' joys_category ' (' title ', ' Alias ', ' SectionID ') VALUES (' Custom Category 1 ', ' Test11 ', 8) [runtime:0.000496s]5.insert into ' joys_category ' (' title ', ' Alias ', ' SectionID ') VALUES (' Custom category ', ' test21 ')                , 8) [runtime:0.000302s] $data [' title ']= "Custom unit"; $data [' Category ']=array (' title ' = ' + ' custom Category 1 ', ' Alias ' = ' test11 '), Array (' Ti                Tle ' = ' + ' custom category ', ' Alias ' = ' test21 '); $sec->relation (True)->add ($data);*//*----Update data/*show COLUMNS from ' joys_section ' [runtime:0.007477s]update ' joys_section ' SET ' id ' =8, ' title ' = ' Custom unit ' W Here (id=8) [runtime:0.002553s]show COLUMNS from ' joys_category ' [runtime:0.008511s]insert into ' joys_category ' (' Ti Tle ', ' Alias ', ' SectionID ') VALUES (' Custom classification ', ' test ', 8) [runtime:0.000866s]show COLUMNS from ' joys_article ' [runtime:0.    011497s] $data [' id ']=8;                Update the time to add $data[' id ']=8, or not update from the table $data [' title ']= "Custom unit";            $data [' Category ']=array (' title ' + ' custom category ', ' Alias ' = ' test ');            $sec->relation (True)->where (' id=8 ')->save ($data); *            */                                        //---------Delete/*DELETE from ' joys_section ' WHERE (' id ' = 8) [runtime:0.002513s]show COLUMNS from ' joys_category ' [runtime:0.01370 9s]delete from ' joys_category ' WHERE (' sectionid ' = 8) [runtime:0.000967s]show COLUMNS from ' joys_article ' [RunTime: 0.014401s]delete from ' joys_article ' WHERE (' sectionid ' = 8) [runtime:0.001064s] $ Sec->relation (True)->delete (8);*/            $data[' ID ']=8;//update the time to add $data[' id ']=8, or not update from the table                $data[' title ']= ' Custom unit '; $data[' Category ']=Array(                    Array(' title ' = ' Custom classification ', ' Alias ' = ' test '))                    ); $sec->relation (true)->where (' id=8 ')->save ($data); $this-display (); }

The correlation model

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.