bad code generation
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| CoughPHP |
High
|
Anthony Bush |
Bug Description
hello, i have this (two) sql tables
CREATE TABLE `network` (
`id` int(11) NOT NULL auto_increment COMMENT 'PK',
`interfaceId` int(11) default NULL COMMENT 'FK_interface_id',
`ipAdresa` varchar(16) collate utf8_czech_ci NOT NULL COMMENT 'ip adresa site',
`maska` int(16) unsigned NOT NULL COMMENT 'maska site',
`ipRouter` varchar(16) collate utf8_czech_ci default NULL COMMENT 'ip adresa routeru',
`verejna` int(1) unsigned NOT NULL default '0' COMMENT 'boolean 1=je verejna / 0=neni verejna',
`isp` enum('sumnet'
PRIMARY KEY (`id`),
KEY `interfaceId` (`interfaceId`),
KEY `verejna` (`verejna`),
KEY `isp` (`isp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=
CREATE TABLE `custPc` (
`id` int(11) NOT NULL auto_increment COMMENT 'PK',
`customerId` int(11) default NULL COMMENT 'FK customer id',
`popis` varchar(50) collate utf8_czech_ci NOT NULL COMMENT 'textovy popis pocitace',
`macAdresa` varchar(12) collate utf8_czech_ci default NULL COMMENT 'mac adresa stroje',
`networkId` int(11) default NULL COMMENT 'FK network id',
`ipAdresa` varchar(16) collate utf8_czech_ci default NULL COMMENT 'ip adresa stroje',
`networkIdVer
`ipAdresaVerejna` varchar(16) collate utf8_czech_ci default NULL COMMENT 'verejna ip adresa stroje',
`down` int(11) default NULL COMMENT 'rychlost downloadu',
`up` int(11) default NULL COMMENT 'rychlost uploadu',
PRIMARY KEY (`id`),
KEY `customerId` (`customerId`),
KEY `networkId` (`networkId`),
KEY `networkIdVerejna` (`networkIdVere
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=
ALTER TABLE `custPc`
ADD CONSTRAINT `custPc_ibfk_2` FOREIGN KEY (`customerId`) REFERENCES `customer` (`usr_id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `custPc_ibfk_3` FOREIGN KEY (`networkId`) REFERENCES `network` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `custPc_ibfk_4` FOREIGN KEY (`networkIdVere
so at brief, there are two relation between this two tables (networkId and networkIdVerejna(in eng.networkIdPu
<?php
/**
* This is the base class for CustPc.
*
* @see CustPc, CoughObject
**/
abstract class CustPc_Generated extends CoughObject {
...omited
public function loadNetwork_
$this-
}
public function getNetwork_Object() {
if (!isset(
$this-
}
return $this->
}
public function setNetwork_
$this-
}
public function loadNetwork_
$this-
}
public function getNetwork_Object() {
if (!isset(
$this-
}
return $this->
}
public function setNetwork_
$this-
}
// Generated one-to-many collection loaders, getters, setters, adders, and removers
...omited
so load/get/
Isn't it ?
i'm testing it on CoughPHP 1.3.2 (2008-09-22)
Adam Janosek
description: | updated |
Anthony Bush (awbush) wrote : | #1 |
Changed in coughphp: | |
assignee: | nobody → awbush |
importance: | Undecided → High |
Anthony Bush (awbush) wrote : | #2 |
This can be resolved a number of ways:
1. Follow the out-of-box convention and use "_id" for ID columns, e.g.:
* Change custPc.networkId to network_id
* Change custPc.
2. Customize the "field_
* Add a line to the `database_
$config[
* Make sure all ID columns end in "Id" (the custPc.
3. Release a change to CoughPHP's one-to-one entity name detection. Out-of-box the generator will try to strip off "_id" and use the result as for method names. In the event it is unable to do this (e.g. column names not following convention), it will use the related table name. This works fine until there is more than one column linking to the same table, as this bug demonstrates. The CoughGeneratorC
I've committed the fix for #3 and will release it on the web site today. I still recommend a schema change to address points #1 or #2, or just make alias methods that don't include the "Id" in the method name, e.g.:
public function getNetwork_Object() {
return $this->
}
public function getNetworkVerej
return $this->
}
Changed in coughphp: | |
status: | New → Fix Committed |
Anthony Bush (awbush) wrote : | #3 |
Changelog/download: http://
Changed in coughphp: | |
status: | Fix Committed → Fix Released |
Thank you for bug report, we will look into this soon.