Changes between Version 2 and Version 3 of relationTypes

Show
Ignore:
Timestamp:
11/04/08 18:01:05 (1 year ago)
Author:
malko (IP: 217.128.159.36)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • relationTypes

    v2 v3  
    1111Most of the time it corresponds to a field in database that points to another table that contains other models. 
    1212 
     13=== hasOne definition as models property === 
     14each ''extended'' abstractModel class has a static property named $hasOne that describe relation between the model and other models it own or belong to. let's explain how this work and how to change parameters defined by the [wiki:modelGeneration modelGenerator] to better sweet our needs. 
     15{{{ 
     16#!php 
     17<?php 
     18class posts extends BASE_POSTS{ 
     19  static protected $hasOne = array( 
     20  // 'relName'=> array('modelName'=>'modelName','relType'=>'ignored|dependOn|requireBy',['localField'=>'fldNameIfNotPrimaryKey','foreignField'=>'fldNameIfNotPrimaryKey','foreignDefault'=>'ForeignFieldValueOnDelete']) 
     21    'user' => array( 
     22      'modelName'=>'users', 
     23      'localField'=>'user', 
     24      'relType'=>'dependOn', 
     25    ), 
     26  ); 
     27} 
     28}}} 
     29so each hasOne relation is defined has an entry in this property. The key used in model::$hasOne property determine how we will access to the related model using a declared instance of this model:  
     30in other words in the previous sample this mean that we can access user of a post like this  
     31{{{  
     32$post = posts::getInstance($instanceId);  
     33$user = $post->user;  
     34}}} 
     35 
     36 
     37each hasOne entry is defined by parameters:  
     38 - modelName : the class name of the extended model related to the current model 
     39 - relType   : one of ignored, dependOn or requireBy see further in this page for more explanation on this. 
     40 - localField : this is the name of the database field name in the table of current model that is the primaryKey of the related model. 
     41 - foreignField : this is the name of the database field name in the table of related model that is referenced in the local field, this only need to be set if it's not the related model primaryKey. 
     42 - foreignDefault: the default value of the foreign field. This is used at delete time to eventually set the foreignField to its default value instead of deleting it too (only used on ignored or dependOn relations). 
     43 
     44 
     45 
    1346== hasMany == 
    1447A hasMany relation is applied everywhere a model has many models as a single property (we will talk of [wiki:modelCollection]). 
     
    1750It can also be a bi-directional hasMany relationship, which reflect most of the time a third table in database that serve to make the link between the two models, just as tags and posts are linked in our sample database by using a table posts_tags. 
    1851 
    19  
    2052== Ignored == 
    2153