Yii Framework Forum: Relations Without Primarykey - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Relations Without Primarykey Rate Topic: -----

#1 User is offline   fabian.h 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 20-July 12

Posted 28 June 2014 - 08:37 PM

I just struggled over a strange behavior with database views and relations for which I couldn't find any solutions on the web. Database views obviously don't have primary keys, but that shouldn't be a problem for the relations defined in the model:
public function relations()
{
	return array(
		'rELATED' => array(self::HAS_MANY, 'Related', array('RelatedID' => 'RelatedID')),
	)
}


The SQL is well formed and gets results when it's queried on the DB server. But the model itself just stays empty as soon as a relation is requested! No Error will be shown or any logs written.
View::model()->with('Related')->findAll());


As soon as a fake PK is manually is defined in the model, everything works fine...
public function primaryKey()
{
	return 'ViewID';
}


I don't really get it why the PK should be defined to use relations, but at least I think there should be an error message instead of just nothing.

System:
Yii 1.1.14
Apache/2.2.21 (Win32)
Microsoft SQL Server 2012 (sqlsrv apache module)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users