Welcome Guest, Not a member yet? Register   Sign In
Call model instance with custom schema
#1

I have a database with multiple schemas, namely dbo and setup both of which have tables that are related to each other via foreign keys, on my CI4 (SPA using svelte 3), I'm calling on of my tables under setup but to no success, I have tried prefixing the $table with the schema i.e.: protected $table = 'setup.table_name';, but that just threw an error because the table name is appended to database_name.dbo<table_name_goes_here>, how do I change this behavior per table? I have several schemas interconnected to my main dbo schema via FKs...
Reply
#2

I'm not sure your case works with CodeIgniter.

At least, the DB connection has a schema:
https://codeigniter4.github.io/CodeIgnit...-of-values
Reply
#3

(09-13-2022, 06:27 PM)kenjis Wrote: I'm not sure your case works with CodeIgniter.

At least, the DB connection has a schema:
https://codeigniter4.github.io/CodeIgnit...-of-values

I did find it after an hour of posting this, leaving this here in case someone else need it (mostly future me):

// override the constructor of the specific model
public function __construct(ConnectionInterface &$db = null, ValidationInterface $validation = null)
{
    parent::__construct($db, $validation); // apply the extended controller's constructor
    $this->db->schema = 'schema_name'; // modify the specific property in this case the db schema
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB