Wednesday, May 26, 2010

Re: hasOne with missing table + habtm

The associations seems to look fine to me!

Please try to answer the rest of my questions in my previous post!
Enjoy,
John

On May 26, 5:03 pm, Paolo <pao...@gmail.com> wrote:
> Hi, thanks for your answer. I show you the code of the models:
>
> User:
>
> class User extends AppModel {
>
>         var $name = 'User';
>
>         var $hasOne = array(
>                 'Author' => array('className' => 'Author',
>                                                         'foreignKey' => 'user_id',
>                                                         'dependent' => false
>                 ),
>                 'Structure' => array('className' => 'Structure',
>                                                         'foreignKey' => 'user_id',
>                                                         'dependent' => false
>                 )
>         );
> ?>
>
> <?php
> class Author extends AppModel {
>
>         var $name = 'Author';
>
>         var $belongsTo = array(
>                                 'User' => array('className' => 'User',
>                                                 'foreignKey' => 'user_id',
>                                                 'conditions' => '',
>                                                 'fields' => '',
>                                                 'order' => ''
>                                 )
>         );
>
>         var $hasAndBelongsToMany = array(
>                         'Game' => array(
>                                 'className' => 'Game',
>                                 'joinTable' => 'games_authors',
>                                 'associationForeignKey' => 'game_id',
>                                 'foreignKey' => 'author_id',
>                                 'with' => 'GamesAuthor'
>                         )
>         );}
>
> ?>
>
> On May 26, 3:57 pm, John Andersen <j.andersen...@gmail.com> wrote:
>
> > Thank you!
>
> > How does your find statement look like? Please show the code.
>
> > How is your association between User and Author defined? Please show
> > the code.
>
> > How is your association between Author and the other model defined?
> > Please show the code.
>
> > The dump didn't give me any clue at all.
>
> > Are your names in accordance with the CakePHP conventions?
> > Model names is camelcased, model filenames are lowercase and
> > underscored!
>
> > Enjoy,
> >    John
>
> > On May 26, 4:37 pm, Paolo <pao...@gmail.com> wrote:
>
> > > I've put pr (debug_backtrace()); die; in the function
> > > ConnectionManager::getDataSource, it seems like the name parameter is
> > > an empty string.
>
> > > The error I get is:
>
> > > Notice (8): Trying to get property of non-object [CORE/cake/libs/model/
> > > datasources/dbo_source.php, line 673]
>
> > > Code | Context
>
> > > $this   =       DboMysql
> > > DboMysql::$description = "MySQL DBO Driver"
> > > DboMysql::$_baseConfig = array
> > > DboMysql::$startQuote = "`"
> > > DboMysql::$endQuote = "`"
> > > DboMysql::$_useAlias = true
> > > DboMysql::$_commands = array
> > > DboMysql::$columns = array
> > > DboMysql::$index = array
> > > DboMysql::$alias = "AS "
> > > DboMysql::$fieldCache = array
> > > DboMysql::$__bypass = false
> > > DboMysql::$__sqlOps = array
> > > DboMysql::$connected = true
> > > DboMysql::$fullDebug = false
> > > DboMysql::$error = NULL
> > > DboMysql::$affected = 1
> > > DboMysql::$numRows = 1
> > > DboMysql::$took = 0
> > > DboMysql::$_result = resource
> > > DboMysql::$_queriesCnt = 0
> > > DboMysql::$_queriesTime = NULL
> > > DboMysql::$_queriesLog = array
> > > DboMysql::$_queriesLogMax = 200
> > > DboMysql::$_queryCache = array
> > > DboMysql::$__descriptions = array
> > > DboMysql::$_sources = array
> > > DboMysql::$connection = resource
> > > DboMysql::$config = array
> > > DboMysql::$configKeyName = "default"
> > > DboMysql::$_transactionStarted = false
> > > DboMysql::$cacheSources = true
> > > DboMysql::$_log = NULL
> > > DboMysql::$results = resource
> > > DboMysql::$map = array
> > > DboMysql::$__booleans = array
> > > $model  =       User
> > > User::$name = "User"
> > > User::$validate = array
> > > User::$hasOne = array
> > > User::$hasMany = array
> > > User::$useDbConfig = "default"
> > > User::$useTable = "users"
> > > User::$displayField = "name"
> > > User::$id = false
> > > User::$data = array
> > > User::$table = "users"
> > > User::$primaryKey = "id"
> > > User::$_schema = array
> > > User::$validationErrors = array
> > > User::$tablePrefix = ""
> > > User::$alias = "User"
> > > User::$tableToModel = array
> > > User::$logTransactions = false
> > > User::$transactional = false
> > > User::$cacheQueries = false
> > > User::$belongsTo = array
> > > User::$hasAndBelongsToMany = array
> > > User::$actsAs = NULL
> > > User::$Behaviors = BehaviorCollection object
> > > User::$whitelist = array
> > > User::$cacheSources = true
> > > User::$findQueryType = "first"
> > > User::$recursive = 1
> > > User::$order = NULL
> > > User::$__exists = NULL
> > > User::$__associationKeys = array
> > > User::$__associations = array
> > > User::$__backAssociation = array
> > > User::$__insertID = NULL
> > > User::$__numRows = NULL
> > > User::$__affectedRows = NULL
> > > User::$_findMethods = array
> > > User::$_log = NULL
> > > User::$Structure = Structure object
> > > User::$Author = NULL
> > > $queryData      =       array(
> > >         "conditions" => array(
> > >         "User.id" => "178"
> > > ),
> > >         "fields" => array(
> > >         "`User`.`id`",
> > >         "`User`.`name`",
> > >         "`User`.`surname`",
> > >         "`User`.`username`",
> > >         "`User`.`password`",
> > >         "`User`.`email`"
> > > ),
> > >         "joins" => array(
> > >         array()
> > > ),
> > >         "limit" => 1,
> > >         "offset" => array(),
> > >         "order" => array(
> > >         null
> > > ),
> > >         "page" => 1,
> > >         "group" => array(),
> > >         "callbacks" => true
> > > )
> > > $recursive      =       null
> > > $null   =       null
> > > $array  =       array()
> > > $linkedModels   =       array(
> > >         "hasOne/Author" => true
> > > )
> > > $_associations  =       array(
> > >         "belongsTo",
> > >         "hasOne",
> > >         "hasMany",
> > >         "hasAndBelongsToMany"
> > > )
> > > $type   =       "hasOne"
> > > $assocData      =       array(
> > >         "className" => "Author",
> > >         "foreignKey" => "user_id",
> > >         "dependent" => false,
> > >         "conditions" => "",
> > >         "fields" => "",
> > >         "order" => "",
> > >         "limit" => "",
> > >         "offset" => "",
> > >         "exclusive" => "",
> > >         "finderQuery" => "",
> > >         "counterQuery" => ""
> > > )
> > > $assoc  =       "Author"
> > > $linkModel      =       null
> > > $external       =       false
> > > $query  =       "SELECT `User`.`id`, `User`.`name`, `User`.`surname`,
> > > `User`.`username`, `User`.`password`, `User`.`email`,
> > > `User`.`user_ip`, `User`.`isAdmin` FROM `users` AS `User`  WHERE
> > > `User`.`id` = 178    LIMIT 1"
> > > $resultSet      =       array(
> > >         array(
> > >         "User" => array(),
> > >         "Author" => array()
> > > )
> > > )
> > > $filtered       =       array(
> > >         "Structure"
> > > )
>
> > >                             $db =& $this;
> > >                         } else {
> > >                             $db =&
> > > ConnectionManager::getDataSource($linkModel->useDbConfig);
>
> > > DboSource::read() - CORE/cake/libs/model/datasources/dbo_source.php,
> > > line 673
> > > Model::find() - CORE/cake/libs/model/model.php, line 2031
> > > AppController::beforeRender() - APP/app_controller.php, line 107
> > > Controller::render() - CORE/cake/libs/controller/controller.php, line
> > > 763
> > > ErrorHandler::_outputMessage() - CORE/cake/libs/error.php, line 373
> > > ErrorHandler::missingTable() - CORE/cake/libs/error.php, line 224
> > > Object::dispatchMethod() - CORE/cake/libs/object.php, line 118
> > > ErrorHandler::__construct() - CORE/cake/libs/error.php, line 118
> > > Object::cakeError() - CORE/cake/libs/object.php, line 203
> > > Model::setSource() - CORE/cake/libs/model/model.php, line 779
> > > Model::__construct() - CORE/cake/libs/model/model.php, line 439
> > > ClassRegistry::init() - CORE/cake/libs/class_registry.php, line 148
> > > Model::__constructLinkedModel() - CORE/cake/libs/model/model.php, line
> > > 666
> > > Model::__generateAssociation() - CORE/cake/libs/model/model.php, line
> > > 751
> > > Model::__createLinks() - CORE/cake/libs/model/model.php, line 640
> > > Model::__construct() - CORE/cake/libs/model/model.php, line 447
> > > ClassRegistry::init() - CORE/cake/libs/class_registry.php, line 140
> > > Model::__constructLinkedModel() - CORE/cake/libs/model/model.php, line
> > > 666
>
> > [snip]

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: