Check if relation exists?


(Serban Cristian) #1

How do you properly check if a model has certain relation?

For now, i am doing:




public function testRelations()

    {

        $model = new Property();

        expect('model has user relation', method_exists($model, 'getUser'))->true();

    }



I have no idea if this is correct or if this is the right way to do it.

If not, how should i go about it ?


(Alirz23) #2

I think that is a reasonable approach to use method_exists to test if a model has certain relation since relationships are declared as methods or you could call the function and check if it returns a result and check that result is valid.


(Serban Cristian) #3

Thank you :)