dfuncd / repofuck

Fucking with the Repository Design Pattern
6 stars 2 forks source link

What happens when Repofuck's `create()` method is called when `$entity` value is a `Builder`? #89

Closed makoru-hikage closed 7 years ago

makoru-hikage commented 7 years ago

For an example:

//Gathering a user's information along with his student's information
//Assuming that the following variables have been defined like this.
//$repofuck->entity = User::leftJoin('students', 'user.id', '=', 'student.user_id');
//$repofuck->data = ...

$repofuck->create();

I still have no idea on how to mitigate it when a developer does it; how shall it be?

makoru-hikage commented 7 years ago

Factors to consider:

  1. Builder class has no save() method
  2. The method map() of Repofuck can't also be used on Builder
  3. I'm quite sure that running the code above shall cause a Fatal error: Call to undefined function

There is prepare() method in Repofuck, but I am still finding a way to use it with Builders, especially the Builders with leftJoin()s.

Do you have any idea?

rmrhz commented 7 years ago

The entity property will no longer be available for public use in the next iteration, as you will need to utilize the prepare function for any manipulation of the entity. For joins however, you can directly call relationships in the entities themselves.

makoru-hikage commented 7 years ago

Will the $entities also be not available for public use?

rmrhz commented 7 years ago

Unfortunately no. Any kind of manipulation should be done over the repositories themselves.

makoru-hikage commented 7 years ago

Calling create() or update() method is impractical when $this->entity is a Builder; there is no need for catching such exception on the developer's side. Such scenario is left to the end user.

Issue is closed for this reason.