Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 197 forks source link

associate() not working #296

Closed AhsanAbrar closed 3 years ago

AhsanAbrar commented 5 years ago

when i use this for EdgeIn like mentioned in docs

$location = Location::find(1922);
$user = User::find(3876);
$relation = $location->associate($user);

got this error:

BadMethodCallException
Method Vinelab\NeoEloquent\Query\Builder::associate does not exist.

where is the problem?

berteltorp commented 5 years ago

How is the the relationship defined in your Location-model?

AhsanAbrar commented 5 years ago
<?php

namespace App;

use Vinelab\NeoEloquent\Eloquent\Model;

class Location extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'Location';

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];

    public function user()
    {
        return $this->belongsTo('App\User', 'LOCATED_AT');
    }
}
alex-jf commented 5 years ago

I had a quick look by my guess is that I should be assigned as this:

$location = Location::find(1922); $user = User::find(3876); $relation = $location->user()->associate($user);

KinaneD commented 5 years ago

You'll need to save after you associate.

hongthach12 commented 5 years ago

me too. solution:

$city = City::first();
$hotel->city()->save($city);

model hotel:
    **
     * Belong to city
     *
     * @return \Vinelab\NeoEloquent\Eloquent\Relations\HasOne
     */
    public function city()
    {
        return $this->hasOne(City::class, 'BELONGS_TO');
    }
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.