I am trying to get data on basis of fields in query param ie
users/1?fields=id,name
its give id and name using findOne
User::findOne(1);
Result:
{
"id": 12,
"name": 'Jhon'
}
When
users?field=id,name
Its give all fields of user Model using findAll()
User::findAll([$ids])
Result:
[
{
'id': 1
'name': abc
'age':30
'dob':1970
'email':abc@test.com
},
{
'id': 2
'name': abc
'age':30
'dob':1970
'email':abc1@test.com
},
Why findAll() not work like findOne() result
softark
(Softark)
January 23, 2020, 11:46am
2
Hi @Faizan_Khattak ,
findAll()
returns an array of ActiveRecord objects (or an empty array), while findOne()
returns a single object (or a null).
@softark you didn’t understand my question?
softark
(Softark)
January 24, 2020, 11:49pm
4
Ah, so you want only id
and name
when you use findAll
?
As far as I know, findOne
should also return age
, dob
and email
. So the difference should lie in your code, not in the difference between findOne
and findAll
.
Could you share your code?
@softark findAll should return only id and name
softark
(Softark)
January 27, 2020, 10:34pm
6
Please explain why you think it should.