2011-10-07 3 views
0

모델 AccountLicense가 있습니다. 어떤 이유에서든 getExpiringLicenes 메소드를 실행할 때 상위 모델 (AccountUser)과의 연관성이 AccountUser의 기본 키가 사용되지 않고 대신 기본 기본 키 'id'. 왜 이런 일이 일어나고 있는지 잘 모르겠습니다. 이것은 모두 플러그인의 일부입니다.잘못된 기본 키를 사용하는 연결된 모델

이 문제에 대한 도움을 주시면 대단히 감사하겠습니다.

SELECT `AccountLicense`.`license_id`, `AccountLicense`.`user_id`, 
`AccountLicense`.`board_id`, `AccountLicense`.`license_number`, 
`AccountLicense`.`license_state`, `AccountLicense`.`license_designation_id`, 
`AccountLicense`.`active_date`, `AccountLicense`.`expire_date`, 
`AccountLicense`.`is_active`, `AccountLicense`.`is_confirmed`, 
`AccountLicense`.`is_primary`, `AccountUser`.`user_id`, `AccountUser`.`user_name`, 
`AccountUser`.`user_pass`, `AccountUser`.`user_status`, `AccountUser`.`user_group`, 
`AccountUser`.`instance_id`, `AccountUser`.`is_logged_in`, `AccountUser`.`is_visible`, 
`AccountUser`.`created_by`, `AccountUser`.`last_modified_by`, 
`AccountUser`.`created_date`, `AccountUser`.`last_modified_date` 
FROM `account_licenses` AS `AccountLicense` 
LEFT JOIN `account_users` AS `AccountUser` 
ON (`AccountLicense`.`user_id` = `AccountUser`.`id`) 
WHERE `AccountLicense`.`expire_date` BETWEEN '2011-10-05' and '2011-11-04' 

이 내 AccountLicenses 모델입니다 :

<?php 
class AccountLicense extends AppModel { 
    var $name = 'AccountLicense'; 
    var $primaryKey = 'license_id'; 
    var $plugin = 'AccountModule'; 

    var $belongsTo = array(
     'AccountUser' => array(
      'className' => 'AccountUser', 
      'foreignKey' => 'user_id' 
     ) 
    ); 


    public function getExpiringLicenses($date = null) 
    { 
     if(is_null($date)) 
      $date = date('Y-m-d',strtotime("+30 days")); 
     return $this->find(
      'all', 
      array(
       'conditions' => array(
        $this->name . '.expire_date BETWEEN ? and ?' =>array(date('Y-m-d'),$date) 
       ) 
      ) 
     );  
    } 
} 
?> 

이이

Warning (512): SQL Error: 1054: Unknown column 'AccountUser.id' in 'on clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 684]

이 실행되고있는 쿼리는 다음과 같습니다

내가 점점 오전 예외 내 계정 사용자 모델 :

,210
<?php 
class AccountUser extends AppModel { 
var $name = 'AccountUser'; 
var $primaryKey = 'user_id'; 
var $actsAs = array('Containable'); 

var $validate = array(
    'user_name'=>array(
     'rule'=>'isUnique', 
     'message'=>'This username has already been taken. Please try again' 
), 
    'user_pass' => array(
     'rule' => array('between', 8, 16), 
     'message' => 'Passwords must be between 8 and 16 characters long.') 

); 

var $hasMany = array(
    'AccountLicense' => array(
     'className' => 'AccountLicense', 
     'foreignKey' => 'user_id' 
    ) 
); 
?> 

답변

1

이다 당신의 연결을 플러그인하는 플러그인 이름을 가져야한다

예이기 때문에 : 당신의 연결이

var $belongsTo = array(
    'AccountUser' => array(
     'className' => 'AccountModule.AccountUser', 
     'foreignKey' => 'user_id' 
    ) 
); 

과 같아야합니다 AccountModule 플러그인 이름 인 경우 또한 잘못이 아니라 올바른 방법은 플러그인 내부에서 모델 클래스를 선언하는 것입니다.

<?php 
class AccountLicense extends AccountModuleAppModel { 

폴더 구조의 올바른 위치에있는 경우 이 라인이 필요 없다는 것을 정확하게 선언했습니다.

var $plugin = 'AccountModule'; 
+0

이러한 변경을해도 여전히 동일한 오류가 발생합니다. – rottmanj

+0

계정 사용자 용 AccountModuleAppModel을 너무 했습니까? appModel에서 확장 한 AccountModuleAppModel을 만들었습니까? 또한 컨트롤러 AccountModuleAppController?는 plugins 폴더 안에있는 폴더 안에있는 모든 것입니까? 그것은 모델을 찾지 못해서 기본 매개 변수를 테이블과 ID로 사용하여 기본 모델을 생성합니다. 이유는 다음과 같습니다. 플러그인에 대한 책 부분을 읽었습니까? – api55

관련 문제