Query does not return all record data

Asked

Viewed 46 times

1

The following query returns the correct record, but missing items on its return.

$nota = $this->Nota->find('first', [
    'conditions' => ['id' => $numero,
        'serie' => $serie
    ]
]);

For example: When not error, returns the full array

array {
    ["id"] => "1"
    ["nome"] => "nome"
    ["serie"] => "serie"
    ["texto"] => "texto"
}

When error returns incomplete array

array {
    ["id"] => "2"
    ["serie"] => "serie2"
    ["nome"] => "nome2"
}

1 answer

2


If they are fields of the same model/table as you say, it is possible to pass the list of fields you want. For example:

$nota = $this->Nota->find('first', [
    'fields' => ['id', 'nome', 'serie', 'texto'],
    'conditions' => ['id' => $numero,
        'serie' => $serie
    ]
]);

If they are fields from another model, you may not have defined the relationships correctly.

  • They are all fields of the same table, but in one moment returns all fields, in another returns only to a certain extent.

  • You tried to pass the list as I’m suggesting?

  • Didn’t it work?! But if Fields is omitted, cake should search all fields, some idea of why it should not be issued?

  • 1

    I don’t know the cause. Maybe some global hook/filter changing Fields if it’s not explicit.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.