Restapi - extraFields - hasMany


(Patrice) #1

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


(Stefano Mtangoo) #2

you need to add expand on your URL


http://api.myurl.com/records?expand=orders