{
    "mode": "perldoc",
    "parameter": "Class::DBI::Relationship",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ADBI%3A%3ARelationship/json",
    "generated": "2026-07-05T09:36:59Z",
    "sections": {
        "NAME": {
            "content": "Class::DBI::Relationship - base class for Relationships\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "A Class::DBI class represents a database table. But merely being able to represent single tables\nisn't really that useful - databases are all about relationships.\n\nSo, Class::DBI provides a variety of Relationship models to represent common database occurences\n(HasA, HasMany and MightHave), and provides a way to add others.\n",
            "subsections": []
        },
        "SUBCLASSING": {
            "content": "Relationships should inherit from Class::DBI::Relationship, and provide a variety of methods to\nrepresent the relationship. For examples of how these are used see\nClass::DBI::Relationship::HasA, Class::DBI::Relationship::HasMany and\nClass::DBI::Relationship::MightHave.\n\nremaparguments\nsub remaparguments {\nmy $self = shift;\n# process @;\nreturn ($class, accessor, $foreignclass, $args)\n}\n\nSubclasses should define a 'remaparguments' method that takes the arguments with which your\nrelationship method will be called, and transforms them into the structure that the Relationship\nmodules requires. If this method is not provided, then it is assumed that your method will be\ncalled with these 3 arguments in this order.\n\nThis should return a list of 4 items:\n\nclass\nThe Class::DBI subclass to which this relationship applies. This will be passed in to you\nfrom the caller who actually set up the relationship, and is available for you to call\nmethods on whilst performing this mapping. You should almost never need to change this.\n\nThis usually an entire application base class (or Class::DBI itself), but could be a single\nclass wishing to override a default relationship.\n\naccessor\nThe method in the class which will provide access to the results of the relationship.\n\nforeignclass\nThe class for the table with which the class has a relationship.\n\nargs\nAny additional args that your relationship requires. It is recommended that you use this as\na hashref to store any extra information your relationship needs rather than adding extra\naccessors, as this information will all be stored in the 'metainfo'.\n\ntriggers\nsub triggers {\nreturn (\nbeforecreate => sub { ... },\naftercreate  => sub { ... },\n);\n}\n\nSubclasses may define a 'triggers' method that returns a list of triggers that the relationship\nneeds. This method can be omitted if there are no triggers to be set up.\n\nmethods\nsub methods {\nreturn (\nmethod1 => sub { ... },\nmethod2 => sub { ... },\n);\n}\n\nSubclasses may define a 'methods' method that returns a list of methods to facilitate the\nrelationship that should be created in the calling Class::DBI class. This method can be omitted\nif there are no methods to be set up.\n",
            "subsections": []
        }
    },
    "summary": "Class::DBI::Relationship - base class for Relationships",
    "flags": [],
    "examples": [],
    "see_also": []
}