hipsterjazzbo / LaraParse

LaraParse provides a nice integration for using Parse (parse.com) with Laravel 5+
MIT License
27 stars 19 forks source link

Create/Update Returns a Generic ParseObject #20

Closed nicklee1990 closed 9 years ago

nicklee1990 commented 9 years ago

When using Create/Update methods in the repository, it returns a generic ParseObject. This prevents me from Type Hinting the object correctly when passing it to methods after creation e.g. say I create a new Sandwich, then I want to fire a new SandwichMade Event, I wouldn't be able to Type Hint the Sandwich in the Event constructor, I'd need to inject it as ParseObject $sandwich. A lunchtime example, but the fix I believe will be to change the Parse Abstract Repo to something along the lines of:

/**
* @param array $data
*
* @return ParseObject
*/
public function create(array $data)
{
    // Haven't tested this at all! 
    $subClass =  ParseObject::getRegisteredSubclass($this->getParseClass());
    $parseClass = new $subClass();
    $this->setValues($data, $parseClass);

    return $parseClass;
}

@HipsterJazzbo sound about right? I noticed this recently when I tried to pass the result of a create operation to my event. Looks as thought it was missing from #14

oflannabhra commented 9 years ago

I just ran into this as well, haha. @nicklee1990 just verifying that your code does indeed return a properly subclassed object. Thanks!

hipsterjazzbo commented 9 years ago

Ah yes. That getRegisteredSubclass method didn't exist in the SDK when I first wrote this, I had to add it and PR it. Go nuts if someone wants to PR a fix for this :)

PS, repository stuff is going to get quite a lot better sometime in the next month or so ;)

oflannabhra commented 9 years ago

PR #35 implements this change. I've been using it in local development but could use it in production as well.

Thanks!