Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic relationships #57

Open
threesquared opened this issue Jan 22, 2015 · 2 comments
Open

Polymorphic relationships #57

threesquared opened this issue Jan 22, 2015 · 2 comments

Comments

@threesquared
Copy link

Is there support for polymorphic relationships? I see there is a check in PathsCommand for polymorphic relationships. However when I run the command on my model it doesn't get past line 159 as the related model is an instance of the ancestor.

I have

namespace App\Models;
use App\Models\Eloquent;
use Iverberk\Larasearch\Traits\SearchableTrait;
class QuoteRequest extends Eloquent
{
    use SearchableTrait;
    /**
     * @return \Illuminate\Database\Eloquent\Relations
     */
    public function details()
    {
        return $this->morphTo();
    }
}

and

namespace App\Models\QuoteRequest\Letting;
use App\Models\Eloquent;
use Iverberk\Larasearch\Traits\TransformableTrait;
use Iverberk\Larasearch\Traits\CallableTrait;
class Details extends Eloquent
{
    use TransformableTrait, CallableTrait;
    /**
     * @return \Illuminate\Database\Eloquent\Relations
     */
    public function quoterequest()
    {
        return $this->morphOne('App\Models\QuoteRequest', 'details');
    }

}

but the path command only returns

{
    "paths": {
        "App\\Models\\QuoteRequest": [

        ]
    },
    "reversedPaths": {
        "App\\Models\\QuoteRequest": [
            ""
        ]
    }
}
@iverberk
Copy link
Owner

This is a tricky one. We actually do use it on polymorphic relations but in our case we would have the searchabletrait on the details class. The path would start looping since the quoterequest would be pointing to itself every time. Not sure what the solution would be here...I'll take some time to think about it and see if I can come up with something.

@mitranos
Copy link

I dont want to bother, but I would like to know how to implement indexing for Polymorphic Relationships. I have the following Models:

class Event extends Model{
use SearchableTrait,

public function eventable()
    {
        return $this->morphTo();
    }
}

Then I have :

class Venue extends Model{
use TransformableTrait, CallableTrait;

 public function events()
    {
        return $this->morphMany('BeNight\Models\Event', 'eventable');
    }

}

class Promoter extends Model{
use TransformableTrait, CallableTrait;

 public function events()
    {
        return $this->morphMany('BeNight\Models\Event', 'eventable');
    }

}

How can I index the event model referencing Venue and Promoters? I have the same problem of @threesquared.
Thanks for your time @iverberk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants