2013-05-07 4 views
5

マイschema.ymlの教義の関係は、一部の組織では、格納された整数値0を持っており、そのようなorganisation_idが存在しない文字列

Organisation: 
    columns: 
    id: { type: integer(4), notnull: true, unique: true, primary: true, autoincrement: true } 
    name: { type: string(100), notnull: true, unique: true } 
    parent_organisation_id: { type: integer(4), notnull: false } 

    relations: 
    ParentOrganisation: { class: Organisation, local: parent_organisation_id, foreignAlias: ChildOrganisations } 

返します。驚いたことに、私はこのコードを実行すると

class organisationActions extends autoOrganisationActions{ 

    public function executeEdit(sfWebRequest $request){ 

     $this->organisation = $this->getRoute()->getObject(); 
     $p = $this->organisation->getParentOrganisationId(); 
     var_dump($p); 

結果は文字列である(1) "0"

なぜこれが整数を返さないので、私は=== 0

+0

こんにちは@jdog、どの環境とスタックを使用しますか? PHPのバージョン、sfのバージョン(1.4私は...)、propelまたは教義? mysqlまたはpostgres?だから私はあなたの問題を再現することができます.... – Matteo

+0

こんにちは@jdog、私の答えはどうですか? – Matteo

+0

こんにちは@jdogどんなニュース? – Matteo

答えて

3

Iを比較することができますいくつかのテストを行い、エンティティのすべての値がすべてのエンティティモデルsfDoctrineRecordの親クラスが_callメソッドで行うという魔法の呼び出しによって返されることがわかります。したがって、call_user_func_arrayの戻り値の型は、文字列やintなどと区別されないようです。実装されたすべてのエンティティのすべてのフィールドで同じ動作をします。idフィールドもあります。で

class Organisation extends BaseOrganisation 
{ 

     public function getParentIdAsIntegerOrNullOtherwise() 
     { 
      $an_id = $this->getParentOrganisationId(); 

      if (! is_null($an_id)) 
      { 
       return intval($an_id); 
      } 

      return NULL; 
     } 
    } 

:次のように操作を比較するために、レコードがnullであるか、最初(ID = 0)であればは、あなたがチェックのためにカスタムゲッターを実装することができます回避策として

ので、コントローラ:

$p = $this->organisation->getParentIdAsIntegerOrNullOtherwise(); 

    var_dump($p); 

それは

NULL 
をダンプします任意の親ノードにリンクされていない場合、これは、ID = 0

希望

が私に教えてください。このヘルプを持つ要素にリンクされている場合、

とは

int(0) 

をダンプしますあなたはそれについて考えます

+0

こんにちは@matteo、これに戻って遅れて申し訳ありません。私は間違いなく、var_dump()のために結果が実際にnullであることを見ています。いずれにせよ、あなたの答えは私が問題を解決するのを助けました。 – jdog

関連する問題