Phalcon, model bindings by field with json string or simple array string -
I want to put table data (json data) in "table_ids" in table 2, eg:
< P> Table_1 | ID | Name | ---------------- | 1 | Title 1 | 2 | Heading 2 | | 3 | Title 3 | 4 | Title 4 Etc ... Table_2
| ID | Table_ID | --------------------- | 1 | "{1,3}" | | 2 | "{3,4,2}" | And, how do I think it is possible to create a relationship in the Falcon model of Table 2, table "field" table_ids "is very much in the form of" table1relation "for table_1 < / P> $ this-> many ('table_Idays', 'Table 1', 'id', array ('nickname' => gt; table1relation ''));
As a result, the object in Table_2 is properly tiered
$ tbl2 = Table2 :: find (); foreign currency ($ id $ tbl2.table1relation) { Echo $ id- & gt; name;};
I am thinking that this is possible Thank you
The first solution is:
Square Table Expands 2 Models {.... // All Items with Mapped Table 1 Model, Public Static Function GetItems () {$ items = Table2 :: find () -> Filters ( Function ($ current_item) {if ($ current_item-> table_ids! = Null) {$ final = array (); $ array = explosion ("," $ current_item-> table_ids); Foreach ($ key = $ x; $ value) {$ table1_item = Table1 :: findFirst ($ Value); Array_push ($ end, $ table1_item);} $ current_item- & gt; Table_ids = $ final;} and {$ current_item- & gt; Returns table_ads = array ();} $ current_item;}); Return $ items; } Before the public event () (if (is_array ($ this-> Table_ID)) {$ cat_value = "" $ id = $ this-> Table_Idays; foreign currency (IDIIT as $ ID $) {$ Cat_value = $ ids_item-> ID; if ($ ID) = $ true) $ cat_value. = ",";} $ $ This-> table_ids = $ cat_value;}}} And now we can use methods in the controller like this
// item items = table 2 :: GetItems (); foreign currency ($ item- & Gt; Table ID as the $ ID) {echo $ id- & gt; name;} ... $ id = new talc 1 (); $ id-> ID = 6; $ id- & gt; name = "title 6" $ items = new table 2 (); $ Item-> ID = 10; $ Item- & gt; ; Table_Ids = $ id; // or $ item-> Table_ID = "1,2,3,4,5"; This job
Comments
Post a Comment