Yii Framework Forum: Restapi - extraFields - hasMany - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Restapi - extraFields - hasMany

#1 User is offline   flaho 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 22-March 13
  • Location:Paris

Posted 06 June 2018 - 03:31 AM

I didn't find a way to return an extraFields containing a collection of records

For example, I can get the supplier data but not the orders

In a model

...
    public function extraFields()
    {
        return ['supplier', 'orders'];
    }


    public function getSupplier()
    {
        return $this->hasOne(Contact:className(), ['id' => 'supplier_id']);
    }

    public function getOrders()
    {
        return $this->hasMany(Order::className(), ['item_id' => 'id']);
    }
...


Sorry but it does work
0

#2 User is offline   Stefano Mtangoo 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 378
  • Joined: 02-January 12
  • Location:Dar es Salaam, Tanzania

Posted 18 June 2018 - 01:34 PM

you need to add expand on your URL
http://api.myurl.com/records?expand=orders


And God said, Let there be science...and it was so! Kwa kazi za Mifumo ya Computer tuone tukusaidie hapa!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users