Answer the question
In order to leave comments, you need to log in
Yii2, how to insert into sql query coalesce field, array from API?
Hello.
--
My background:
There is a third-party API - https://www.bridgeinteractive.com
Documentation - https://rets.ly/docs/platform/
This API simply outputs property data as json
There is a Yii2 application that has its own API which also outputs data in the form of json
I'm trying to combine the SQL query from ActiveRecord with the json received from another API.
Maybe I'm doing something wrong, or it's impossible to do this, because you can't make a connection with the Bridge API.
During a collision, I only get a key, by which I can then pull out real estate data.
It turns out a view of all deals, and getting one specific deal that gives data in the form of JSON.
The problem is that I need to make two requests for two APIs, and already at the front, link the two received json into one.
For you to understand, I can set an SQL query, something like:
SELECT d.*, coalesce(o.key, 0) as realestate FROM deals ...
o.key === Bridge API
, if there is no data, and to avoid errors, I fill the empty cell with zero, and the column where to arrive data from the Bridge API I will call for example "realestate". hasOne
I tried, but apparently I'm not doing something right.public function getRealestate(){
return $this->hasOne(...);
}
Deals::find()->with('realestate')->where(['key' => $key])->asArray()->all();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question