2010-07-05 4 views
2

J'essaie de créer un modèle de correspondance qui inclut les joueurs alignés pendant ce match. Chaque match a donc de nombreux joueurs et chaque joueur a de nombreux matches.MongoDB et CakePHP Associations du modèle

match = { 
'_id' : ObjectID('978tqwbi9873gofiu'), 
'home' : 'Argentina', 
'away' : 'Brazil', 
'lineup-home' : [ 
    {'name' : 'Lionel Messi', 
    'goals' : '2', 
    'timeon' : 30 
    }, 
    {'name' : 'Diego Maradonna', 
    'goals' : '0', 
    'timeon' : 0 
    }, 
    {'name' : 'Sergio Aguero', 
    'goals' : '0', 
    'timeon' : 0 
    } 
] 
} 

Comment puis-je ajouter ces relations « line-up maison » dans mon modèle CakePHP travailler avec mon MongoDB? Voici à quoi ressemble mon modèle ...

class Match extends AppModel { 
    //var $useDbConfig = 'mongo'; 
    var $mongoSchema = array(
     'home' => array('type' => 'string'), 
     'away' => array('type' => 'string'), 
     'lineup-home' => ??? 
    ); 
} 

Merci.

+0

Avez-vous déjà trouvé une solution, j'ai la même question? –

Répondre

0

Je pense que l'utilisation de 'gamme-home' => 'array' fera l'affaire ..

+0

Etes-vous sûr? Il semble quelque peu étrange et cela ne semble pas fonctionner: var $ mongoSchema = array ( 'home' => tableau ('type' => 'chaîne'), 'absent' => tableau ('type' = > 'chaîne'), 'lineup-home' => array ('type' => 'array') ); – octavian

0

Et que diriez-vous

var $mongoSchema = array(
     'home' => array('type' => 'string'), 
     'away' => array('type' => 'string'), 
     'lineup-home' => array(
      'name' => array('type' => 'string'), 
      'goals' => array('type' => 'string'), 
      'timeon' => array('type' => 'integer'), 
     ) 
    ); 
0

Vous pouvez utiliser ce schéma:

var $mongoSchema = array(
     'home' => array('type' => 'string'), 
     'away' => array('type' => 'string'), 
     'lineup-home' => array(
      array(
       'name' => array('type' => 'string'), 
       'goals' => array('type' => 'string'), 
       'timeon' => array('type' => 'integer'), 
      ) 
     ) 
    ); 
Questions connexes