烘焙模型时不需要的belongsTo关联,其中fieldname包含“_id”

时间:2014-07-24 19:29:22

标签: php cakephp

当我烘烤一个有" _id"在fieldname的中间,它将创建不需要的belongsTo关联。

使用Cake Bake 2.4.5。

违规领域:

  • ora_set_metadata_id_default_to_sql_true
  • sqlserver_use_ansi_quoted_identifiers

表架构

CREATE TABLE IF NOT EXISTS data_source_names(
  id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) DEFAULT NULL,
  description VARCHAR(255) DEFAULT NULL,
  ora_tsn_service_name VARCHAR(255) DEFAULT NULL,
  ora_enable_result_sets TINYINT(1) DEFAULT NULL,
  ora_enable_query_timeout TINYINT(1) DEFAULT NULL,
  ora_read_only_connection TINYINT(1) DEFAULT NULL,
  ora_enable_closing_cursors TINYINT(1) DEFAULT NULL,
  ora_enable_thread_safety TINYINT(1) DEFAULT NULL,
  ora_batch_autocommit_mode VARCHAR(255) DEFAULT NULL,
  ora_numeric_settings TINYINT(1) DEFAULT NULL,
  ora_fetch_buffer_size TINYINT(1) DEFAULT NULL,
  ora_enable_lobs TINYINT(1) DEFAULT NULL,
  ora_enable_statement_caching TINYINT(1) DEFAULT NULL,
  ora_cache_buffer_size TINYINT(1) DEFAULT NULL,
  ora_enable_failover TINYINT(1) DEFAULT NULL,
  ora_retry INT(10) DEFAULT NULL,
  ora_delay INT(10) DEFAULT NULL,
  ora_bind_timestamp_as_date TINYINT(1) DEFAULT NULL,
  ora_disable_sql_describe_param TINYINT(1) DEFAULT NULL,
  ora_force_sql_wchar_support TINYINT(1) DEFAULT NULL,
  ora_bind_number_as_float TINYINT(1) DEFAULT NULL,
  ora_disable_microsoft_transaction_server TINYINT(1) DEFAULT NULL,
  ora_disable_rule_hint TINYINT(1) DEFAULT NULL,
  ora_set_metadata_id_default_to_sql_true TINYINT(1) DEFAULT NULL,
  ora_enable_exec_syntax TINYINT(1) DEFAULT NULL,
  ora_schema VARCHAR(255) DEFAULT NULL,
  sqlserver_use_sql_server_authentication TINYINT(1) DEFAULT NULL,
  sqlserver_network_libraries VARCHAR(255) DEFAULT NULL,
  sqlserver_dynamically_determine_port TINYINT(1) DEFAULT NULL,
  sqlserver_port_number INT(10) DEFAULT NULL,
  sqlserver_change_the_default_database_to VARCHAR(255) DEFAULT NULL,
  sqlserver_attach_database_filename VARCHAR(255) DEFAULT NULL,
  sqlserver_create_temporary_stored_procedures VARCHAR(255) DEFAULT NULL,
  sqlserver_use_ansi_quoted_identifiers TINYINT(1) DEFAULT NULL,
  sqlserver_use_ansi_nulls_padding_warnings TINYINT(1) DEFAULT NULL,
  sqlserver_use_failover_sql_server TINYINT(1) DEFAULT NULL,
  sqlserver_change_the_language_of_sql_server_system_messages_to VARCHAR(255) DEFAULT NULL,
  sqlserver_use_strong_encryption_for_data TINYINT(1) DEFAULT NULL,
  sqlserver_perform_translation_for_character_data TINYINT(1) DEFAULT NULL,
  sqlserver_use_regional_settings TINYINT(1) DEFAULT NULL,
  sqlserver_save_long_running_queries_to_log_file VARCHAR(255) DEFAULT NULL,
  sqlserver_log_odbc_driver_statistics_to_log_file VARCHAR(255) DEFAULT NULL,
  created DATETIME DEFAULT NULL,
  modified DATETIME DEFAULT NULL,
  created_by INT(10) UNSIGNED DEFAULT NULL,
  modified_by INT(10) UNSIGNED DEFAULT NULL,
  PRIMARY KEY (id)
)
ENGINE = INNODB
AUTO_INCREMENT = 1
CHARACTER SET utf8
COLLATE utf8_unicode_ci;

不需要的belongsTo关联:

/**
 * belongsTo associations
 *
 * @var array
 */
public $belongsTo = array(
    'OraSetMetadataDefaultToSqlTrue' => array(
        'className' => 'OraSetMetadataDefaultToSqlTrue',
        'foreignKey' => 'ora_set_metadata_id_default_to_sql_true',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    ),
    'SqlserverUseAnsiQuotedentifiers' => array(
        'className' => 'SqlserverUseAnsiQuotedentifiers',
        'foreignKey' => 'sqlserver_use_ansi_quoted_identifiers',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);

1 个答案:

答案 0 :(得分:1)

这是一个已在2.4.7中修复的错误

<强> https://github.com/cakephp/cakephp/issues/3230

以前烘焙只会在字段名称的任何位置搜索字符串_id(而不是在字母结尾处),这会导致您遇到的错误发现。