Hello.
I am trying to create a new website. Currently i am very pleased with working with yii. Still having some Foreign key issues.
My problem is this:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'players.playerid' in 'where clause'
The database is from a game im trying to setup.
a "Base" allways has an owner but not allways an occupier.
Any ideas on how to handle it in the relations when i relate to all the bases the player has?
Data structures and relations:
Players model:
return array(
"bases" => array(self::HAS_MANY,"Bases","playerid",
'condition'=> "players.playerid = bases.ownerid"
),
"occupied_bases" => array(self::HAS_MANY,"Bases","playerid"),
"fleets" => array(self::HAS_MANY,"Fleet","ownerid")
);
Bases model:
return array(
'planet' => array(self::BELONGS_TO,"Planets", "baseid"),
'owner' => array(self::BELONGS_TO, "Players","ownerid"),
'occupier' => array(self::HAS_ONE,"Players","occupierid"),
'commander' => array(self::HAS_ONE,"Commanders","commanderid"),
'structures' => array(self::HAS_MANY,"Structures","baseid")
);
Players SQL:
CREATE TABLE `players` (
`playerid` int(11) NOT NULL,
... (more unnessesary coloums)
UNIQUE KEY `playerid` (`playerid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Bases SQL:
CREATE TABLE `bases` (
`baseid` int(11) NOT NULL,
`name` varchar(30) NOT NULL,
...
`ownerid` int(11) DEFAULT '0',
`occupierid` int(11) DEFAULT '0',
`commanderid` int(11) DEFAULT '0',
UNIQUE KEY `baseid` (`baseid`),
KEY `ownerid` (`ownerid`),
KEY `occupierid` (`occupierid`),
KEY `commanderid` (`commanderid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `bases`
ADD CONSTRAINT `bases_ibfk_14` FOREIGN KEY (`commanderid`) REFERENCES `commanders` (`commanderid`),
ADD CONSTRAINT `bases_ibfk_11` FOREIGN KEY (`baseid`) REFERENCES `planets` (`baseid`),
ADD CONSTRAINT `bases_ibfk_12` FOREIGN KEY (`ownerid`) REFERENCES `players` (`playerid`),
ADD CONSTRAINT `bases_ibfk_13` FOREIGN KEY (`occupierid`) REFERENCES `players` (`playerid`);
Page 1 of 1
[SOLVED] Foreign key problem Need help with this piece of code.
#3
Posted 08 May 2010 - 04:07 PM
Giving same error:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.playerid' in 'where clause'
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't.playerid' in 'where clause'
#4
Posted 08 May 2010 - 04:43 PM
I found the problem. Still i had tried that before.
return array(
"bases" => array(self::HAS_MANY,"Bases","ownerid",
),
"occupied_bases" => array(self::HAS_MANY,"Bases","playerid"),
"fleets" => array(self::HAS_MANY,"Fleet","ownerid")
);
the only thing changed is playerid is set to ownerid...
return array(
"bases" => array(self::HAS_MANY,"Bases","ownerid",
),
"occupied_bases" => array(self::HAS_MANY,"Bases","playerid"),
"fleets" => array(self::HAS_MANY,"Fleet","ownerid")
);
the only thing changed is playerid is set to ownerid...
Share this topic:
Page 1 of 1

Help












