1
我對unpeltanding的propel處理enum-columns(使用Propel 1.6.9和MySQL)非常惱火。它似乎總是返回默認值。推動總是選擇枚舉列的默認值?
的CREATE-聲明表:
CREATE TABLE IF NOT EXISTS `offerVariant` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`offerID` int(11) unsigned NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
[1] -> `amountType` enum('entity','person') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'entity',
`unitCount` smallint(5) unsigned DEFAULT NULL,
[2] -> `priceType` enum('per night','per day','per hour','flat rate') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'per night',
`tax` tinyint(3) NOT NULL DEFAULT '7',
`maxPrice` decimal(12,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`id`),
KEY `offerID` (`offerID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;
這是我的schema.xml中的相關部分:
<table name="offerVariant">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="offerID" type="integer" size="11" required="true" />
<column name="name" type="varchar" size="255" required="true" />
<column name="description" type="longvarchar" required="true" />
[1] -> <column name="amountType" type="enum" valueSet="entity, person" sqlType="ENUM('entity','person')" required="true" />
<column name="unitCount" type="smallint" size="5" required="false" />
[2] -> <column name="priceType" type="enum" valueSet="per night, per day, per hour, flat rate" sqlType="ENUM('per night','per day','per hour','flat rate')" required="true" />
<column name="tax" type="tinyint" size="3" required="true" />
<column name="maxPrice" type="decimal" size="14" required="true" />
<foreign-key foreignTable="offer" refPhpName="offerVariant">
<reference local="offerID" foreign="id"/>
</foreign-key>
</table>
我有2枚舉列,amountType and priceType。 我從這個表
- 一個選擇2行與amountType == 實體 | priceType == 每晚
- 一個與amountType == 人 | priceType == 每天
amountType的默認值是priceType每晚的實體。
我取行是這樣的:
public function selectVariantsByOffer($offerid){
$variants = OffervariantQuery::create()
->filterByOfferId($offerid)
->find();
return $variants;
}
和回報是:
[0] => Offervariant Object
(
[startCopy:protected] =>
[id:protected] => 1
[amounttype:protected] => 0
[pricetype:protected] => 0
[...]
)
[1] => Offervariant Object
(
[startCopy:protected] =>
[id:protected] => 2
[amounttype:protected] => 0
[pricetype:protected] => 0
[...]
)
使用干將後:
[0] => Array ( [id] => 1 [...] [amountType] => entity [priceType] => per night ) [1] => Array ( [id] => 2 [...] [amountType] => entity [priceType] => per night )
完全錯誤的。
我讀到了有關Propel以另一種方式解釋type =「enum」的事實,而不是MySQL的做法,並且認爲在schema.xml中設置sqlType是非常必要的。我按照上面提到的那樣做了重建,但沒有改變。
- 是不是可以獲取指定的枚舉值?
- 或者是我的schema.xml不正確?
- 還是我錯誤的方式?
我做了它的varchar方式,它的作品就像一個魅力。謝謝! – 32bitfloat
是的,這是絕對有效的..我也使用該varchar解決方案 –
只是做了相同的w /'text'字段,'type =「VARCHAR」sqlType =「TEXT」',因爲我不想對待文本字段就像PHP中的數組一樣。 – quickshiftin