jurietylier's avatar

How to Exclude null relation in laravel eloquent oracle and mysql relation

{ "rn": "1", "supplier": "700030", "sup_name": "test-supp", "contracts": null } this is the piece of an example the supplier is oracle database while the contracts is mysql how to exclude that im using with method in laravelController and belongsTo in model i want to exclude if the relation is null

0 likes
9 replies
Tray2's avatar

You can do

->whereNotNull('contracts')
jurietylier's avatar

@Tray2 it throws error sir $data = Supplier::with('contracts') ->paginate(10); this is my query in controller by the way the Supplier is Oracle db while the contracts inside in with method is mysql db

Tray2's avatar

@jurietylier Who the hell made that design decision? You should stay in the same rdbms, not mix them.

So, you query one table in the Oracle database, and then you want to fetch an related model from an MySQL database?

I'd say that it sounds like a really bad idea.

Which of the databases is the main application database?

I suggest moving all data into a single database schema, it will make your life much easier.

1 like
jurietylier's avatar

@Tray2 the oracle database is reference database only but id want to sort the oracle and get the related model in mysql

Tray2's avatar

@jurietylier I would then create a database view, in your mysql schema that loads the data you need from your oracle db.

You will have to google how to connect from MySQL to Oracle, the other way around you can use a Oracle Database Gateway.

The easiest would be to export all the tables you need from the oracle database and import them into mysql, or the other way around.

So in general terms, pick one db and stick to it.

1 like

Please or to participate in this conversation.