DBIx::HTMLView::N2N - A many to many relation between two tabels
$fld=$post->fld('testf'); print $fld->view_html;
This is a subcalss of DBIx::HTMLView::Relation used to represent N2N relations in the databse as well as the data contained in them. Se the DBIx::HTMLView::Relation and DBIx::HTMLView:.Fld (the superclass of Relation) manpage for info on the methods of this class.
A N2N relation as where each post in one table can be related to any number of posts in an other table. As for example in the User/Group table pair example described in the tutorial where each user can be part of several groups.
A third table, called link table, will be used to represent the relations. It should contain three fields. One id field (as all tabels), one from id (eg user id) and one to id (eg group id). Now one relation consists of a set of posts in this table each linking one from post (eg user) to one to post (eg group).
As for the overall operation this kind of Flds should wokr like any other Fld, but you can also do a few extra things, as described below.
The constructor works in the exakt same way as for DBIx::HTMLView::Fld, se it's man page for details.
The following parameters passed within the $data has is recognised:
tab - The table this table is related to (to table) from_field - The field name of the link table where the from table post id is stored. Default is "<from table>_id". to_field - The field name of the link table where the to table post id is stored. Default is "<to table>_id". lnk_tab - The name of the link table. Default is "<from table>_to_<to table>". id_name - The name of the link post id field in the link table. Default is "id". view - String used when viewing a related post withing the post being viewed (eg the groups list of a user post). All $<fld name> constructs will be replaced with the data of the post beeing viewed. join_str - As a post can be related to several other and each will be viewed using the view string above and then joined together using this string as glue. Default is ", ". extra_sql - Extra sql code passe to the list method when listing related posts. This can for example be used to specify in which order related posts should be viewed. Default is "ORDER BY <to table id name>".
As you se, it is only tab and view that does not have any default valu, so those two has to be defined within the table declaration.
Returns the database handle of the tabels.
Returns the id of the post this relation belongs to.
Returns the name of the to table.
Returns the DBIx::HTMLView::Table object representing the to table.
Returns the name of the from field in the link table as specified in the $data param to the constructor.
Returns the name of the to field in the link table as specified in the $data param to the constructor.
Returns the name of the link table as specified in the $data param to the constructor.
Returns the name of the link post id field in the link table as specified in the $data param to the constructor.
Creates and returns a DBIx::HTMLView::Table object representing the link table.
Returns the join_str parameter as specified in the $data param to the constructor.
Returns the extra_sql parameter as specified in the $data param to the constructor.
Returns true if we have a post set. Se the post_set method.
When this object is used to represent the data of a relation that can be done in two ways. Either we just know the id of the post we belong to and can look up the related posts from the db whenever needed. When such a post lookup is done the (parts of the) posts returned are stored in a DBIx::HTMLView::PostSet object.
This method will return such an object after selecting it from the server if nesessery. You can use the got_post_set method to check if it was already donwloaded. If this Fld did not belong to a specifik post, eg no id was defiedn it will die with "Post not defined!".
Will return an array of the posts after calling the post_set method. If there are no related posts it will not die, but return an empthy array.
Will generate a view of the post $p, as described by the view parameter specified in the $data parameter to the constructor.
Will view the related posts as defined by the view and join_str parameters specified in the $data parameter to the constructor
Returns a string containing "<input type=checkbox ...>" constructs to allow the user to specify which posts we should be related to. All posts in the to table will be listed here.
Will remove the relation from post $id. Eg it will no longer be related to any posts.
Updates the link table and returns a empthy array as no fields in the from table should be modifed.
Used by the DBIx::HTMLView::Selection object $sel when it finds a relation->field construct in a search string that should be evaled into an sql select expretion. $sub will be a refference to an array of all names after the -> signs, eg for rel1->rel2->rel3->field $sub would contain ("rel2", "rel3", "field") and this would be the rel1 relation.
Returns undef as we've not got any field in the main table. Se DBIx::HTMLView::Fld.
To install DBIx::HTMLView, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::HTMLView
CPAN shell
perl -MCPAN -e shell install DBIx::HTMLView
For more information on module installation, please visit the detailed CPAN module installation guide.