ActiveRecord nested Loading: Bug or my fault?`

Hi there, Im not sure if I am doing right, I user the following database structure

Users:

[sql]

CREATE TABLE

“User” id integer NOT NULL DEFAULT nextval(‘user_id_seq’::regclass)

CONSTRAINT

user_pkey PRIMARY KEY (id)

[/sql]

User related abilities

[sql]

CREATE TABLE "UserAbilities"

(

id bigserial NOT NULL,

"userID" integer NOT NULL,

"abilityID" integer NOT NULL,

CONSTRAINT "UserAbilities_pkey" PRIMARY KEY (id),

CONSTRAINT "UserAbilities_AbilityID" FOREIGN KEY ("abilityID")

  REFERENCES "Abilities" (id) MATCH SIMPLE


  ON UPDATE RESTRICT ON DELETE RESTRICT,

CONSTRAINT "UserAbilities_UID" FOREIGN KEY ("userID")

  REFERENCES "User" (id) MATCH SIMPLE


  ON UPDATE RESTRICT ON DELETE CASCADE,

CONSTRAINT "UserAbilities_userID_key" UNIQUE ("userID", "abilityID")

}

[/sql]

And an ability list

[sql]

CREATE TABLE "Abilities"

(

id integer NOT NULL DEFAULT nextval(’“AbilityList_id_seq”’::regclass),

"name" character varying(60) NOT NULL,

name_en character varying(60) NOT NULL,

name_de character varying(60) NOT NULL,

CONSTRAINT "AbilityList_pkey" PRIMARY KEY (id)

)

[/sql]

And the model relations




class User extends CActiveRecord {

  public functions relations() {

    return array(

      'userAbilities' => array(self::HAS_MANY, 'UserAbilities', 'userID'),

      //other relations

    );

  }

}


class UserAbilities extends CActiveRecord {

  public functions relations() {

    return array(

      'user' => array(self::BELONGS_TO, 'User', 'userID'),

      'ability' => array(self::BELONGS_TO, 'Abilities', 'abilityID'),

    );

  }

}


class Abilities extends CActiveRecord {

  public functions relations() {

    return array(

      'userAbilities' => array(self::HAS_MANY, 'UserAbilities', 'abilityID'),

    );

  }

}



I tried to retrieve the user related ability from the list via the UserAbility Junction Table in a Portlet. The Portlet has to getData methods, on is working the other throws the following error:

Relation "abilities" is not defined in active record class "User".




class UserAbilitiesPortlet extends Portlet {

	

	public $title='Fähigkeiten';

	public $data = array();

	

	function renderContent() {

		$this->data = $this->getDataWorking();

		$this->render('userAbilitiesPortlet');

	}

	

	function getDataWorking() {

		$user = User::model()->with('userAbilities')->findByPk($_GET['id']);

		return array();

	}

	

	function getDataNotWorking() {

		$user = User::model()->with(array('userAbilities'=>'abilities'))->findByPk($_GET['id']);

		return array();

	}

}



Any idea whats going wrong?

You defined the relation as ‘ability’ not ‘abilities’.