Skip to content

morphTo #8067

Closed
Closed
morphTo#8067
@alesl

Description

@alesl

morphTo relation is not being properly loaded when type and id of related model is null.

Example:

class Photo extends \Eloquent {
  public function imageable() {
    return $this->morphTo();
  }
}

class Staff extends \Eloquent {
  public function photos() {
    return $sthis->morphMany('Photo', 'imageable');
  }
}

// when creating new model
$photo = new Photo();
print $photo->imageable()->toSql();
// prints: select * from `photos` where `photos`.`` is null

// when loading existing model with imageable_type===null
print Photo::find(1)->imageable()->toSql();
// prints: select * from `photos` where `photos`.`` is null

// ... or
print Photo::find(1)->imageable;
// expect null, instead exception is thrown (bad query as seen in previous two examples)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions