Model Table Problem

Hi all,
I am just develloping an app where a table ‘offices’ exsists.
I have baked the controller, Model and Views. Now it turns out, I can store new data but the data is not retreived from mysql. There is no error displayed and the app is not interrupted. No info for identifying the error.
I have installed the latest cakephp version.
Any idea where I can start making more research?

This is the code on OfficesTable.php:
class OfficesTable extends Table
{

/**
 * Initialize method
 *
 * @param array $config The configuration for the Table.
 * @return void
 */
public function initialize(array $config)
{
    parent::initialize($config);

    $this->table('offices');
    $this->displayField('id');
    $this->primaryKey('id');

    $this->belongsTo('Cities', [
        'foreignKey' => 'city_id',
        'joinType' => 'INNER'
    ]);
    $this->belongsTo('Persons', [
        'foreignKey' => 'person_id',
        'joinType' => 'INNER'
    ]);
    $this->hasMany('Events', [
        'foreignKey' => 'office_id'
    ]);
}

/**
 * Default validation rules.
 *
 * @param \Cake\Validation\Validator $validator Validator instance.
 * @return \Cake\Validation\Validator
 */
public function validationDefault(Validator $validator)
{
    $validator
        ->integer('id')
        ->allowEmpty('id', 'create');

    $validator
        ->requirePresence('office', 'create')
        ->notEmpty('office');

    $validator
        ->requirePresence('street', 'create')
        ->notEmpty('street');

    $validator
        ->requirePresence('no', 'create')
        ->notEmpty('no');

    $validator
        ->requirePresence('phone', 'create')
        ->notEmpty('phone');


    return $validator;
}

/**
 * Returns a rules checker object that will be used for validating
 * application integrity.
 *
 * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
 * @return \Cake\ORM\RulesChecker
 */
public function buildRules(RulesChecker $rules)
{
    $rules->add($rules->isUnique(['email']));
    $rules->add($rules->existsIn(['city_id'], 'Cities'));
    $rules->add($rules->existsIn(['person_id'], 'Persons'));

    return $rules;
}

}

Have you checked the content of the table in your database ?

Hi, yes I have done. And now I am a step forward. I have entere a number in the field person_id and the row is diplayed. The problem is the ‘belongsTo’ option. I’m going to check a better solution.

Is your id field in autoincrement ?

But by the way: Do you know cake is sometimes is offering only the id and sometimes the fullname of a table with two columns? Like : Cities with columns id and name. When one uses in a form as options.
Regards Klaus

That’s weird, but maybe it comes from your table structure… I remember issues with no autoincrement fields on numeric PKs or with varchar PKs.

If you use the ‘cities’ table in a relation with another one, if the cities.id is required but cake can’t automatically determine it, the ‘id’ field will be present in the forms of related content.

And maybe you updated the table and forget to re bake/build all the MVC…

Thanks for your ideas. I will follow up later - now I have a meeting. Regards

Hi, stupid. It was the case of ‘displayField’.
And the first issue was related to a wrong value in a ‘belongsTo-Relation’.
No further input needed. How do I close this post?