0

I have had my Models relationships defined the traditional way and it has been working fine. However, I started using Ardent to make validation easier, and noticed that it has a useful feature for defining Eloquent relationships.

https://github.com/laravelbook/ardent#relations

To put this in to context, I have a User model, that belongs_to a Location (geographic in this instance).

Before, I would use:

public function location(){
    return $this->belongsTo('Location', 'location');
}

and I had no problems whatsoever. Changing over to the Ardent way of doing it has produced:

protected static $relationsData = array(
    'location' => array(self::BELONGS_TO, 'Location', 'foreignKey' => 'location')

    );

Which always returns null rather than the Users location.

User.php

use LaravelBook\Ardent\Ardent;

class User extends Ardent implements UserInterface, RemindableInterface {

    protected static $table = 'agents';
protected static $relationsData = array(
    'location' => array(self::BELONGS_TO, 'Location', 'foreignKey' => 'location')

    );

}

Database agents id: int(11) PK location: int(11) FK(locations.id)

*locations*
    id: int(11) PK
    longtext: text

I have no idea why this is now not returning anything anymore as it is the same just different syntax.

I could just go back to the Laravel way of doing it, but I like Ardent's syntax more.

Terrawheat
  • 21
  • 1
  • 3

1 Answers1

0

Simple case of column name/relationship collision.

Terrawheat
  • 21
  • 1
  • 3