tighten / parental

Use single table inheritance in your Laravel app
MIT License
1.36k stars 98 forks source link

FR: Determining Model from type column in relationship. #90

Closed madsem closed 1 year ago

madsem commented 4 years ago

Hey,

great package, thanks a lot for this.

I'm testing it atm, and it does seem to work wonderfully. I am just wondering if it wouldn't be a good idea to allow getting the type from a relationship, rather than having to add the column to every table?

Let me elaborate:

// the main parent
class Customer extends Model {

   // type column: for example Google, Microsoft, Twitter etc. 
    protected $platform;
}

class Account extends Model {

public function customer()
    {
        return $this->belongsTo(Customer::class, 'remote_customer_id');
    }
}

class Campaign extends Model {

public function account()
    {
        return $this->belongsTo(Account::class, 'remote_account_id', 'remote_account_id');
    }

}

class Keyword extends Model {

public function account()
    {
        return $this->belongsTo(Account::class, 'remote_account_id', 'remote_account_id');
    }
}

Now all these Models under a Customer model, could be for example a TwitterKeyword, or MicrosoftCampaign etc. Theoretically in a case like this, creating an additional type column on each of these sub-models will create a lot of unnecessary data.

Is this something you think makes sense in the scope if this project?

mattstauffer commented 1 year ago

Hey friends! The team at Tighten has taken Parental back over and we're re-opening the issue tracker, but to give us a clean slate, I'm going to close all old issues that remain from when Caleb closed the issue tracker in 2020. If this is still an outstanding concern with the latest version of Parental, please feel free to open a new issue referencing this one.

Thank you!