Welcome Guest, Not a member yet? Register   Sign In
Model within a model
#12

That is not a good practice. However, to get past your current situation, you can do lazy loading of the needed models. That is, you do not load them on the needing models' instantiation. You can do something like this.
PHP Code:
class Settings_model extends \App\Models\BaseModel
{
    public 
$users;
    public function 
setUserModel(User_model $users)
    {
        
$this->users $users;
        return 
$this;
    }
}

// When creating the models, you can this;
$users model('Users_model');
$settings model('Settings_model');

// now your settings model has an instance of users model
// you can do the same with users
// but beware that this may cause memory leaks
$settings->setUserModel($users); 
Reply


Messages In This Thread
Model within a model - by LuxesR - 06-29-2021, 12:31 PM
RE: Model within a model - by BilltheCat - 06-29-2021, 12:52 PM
RE: Model within a model - by LuxesR - 06-29-2021, 01:47 PM
RE: Model within a model - by BilltheCat - 06-29-2021, 02:06 PM
RE: Model within a model - by paulbalandan - 06-30-2021, 12:54 AM
RE: Model within a model - by InsiteFX - 06-30-2021, 01:58 AM
RE: Model within a model - by LuxesR - 06-30-2021, 02:49 AM
RE: Model within a model - by paulbalandan - 06-30-2021, 07:07 PM
RE: Model within a model - by LuxesR - 07-01-2021, 02:58 AM
RE: Model within a model - by paulkd - 07-01-2021, 12:36 AM
RE: Model within a model - by ikesela - 07-01-2021, 02:59 AM
RE: Model within a model - by paulbalandan - 07-01-2021, 04:25 AM
RE: Model within a model - by LuxesR - 07-01-2021, 05:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB