<?php
/**
* This is the model class for table "nazioni".
*
* The followings are the available columns in table 'nazioni':
* @property string $nome
* @property string $codice
*
* The followings are the available model relations:
* @property Utente[] $utentes
* @property Utente[] $utentes1
*/
class Nazioni extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Nazioni the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'nazioni';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('nome, codice', 'required'),
array('nome', 'length', 'max'=>45),
array('codice', 'length', 'max'=>4),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('nome, codice', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'utentes' => array(self::HAS_MANY, 'Utente', 'nazioni_nome'),
'utentes1' => array(self::HAS_MANY, 'Utente', 'nazioni_codice'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'nome' => 'Nome',
'codice' => 'Codice',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('nome',$this->nome,true);
$criteria->compare('codice',$this->codice,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
Ciao è la pirma cosa che avevo provato ma mi continuava a dare questo errore. E lo fa anche adesso che ci ho riprovato.
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘CH’ in ‘where clause’. The SQL statement executed was: SELECT * FROM nazionit WHERE CH LIMIT 1
Il find in che colonna cerca non glie lo devo dire ?
Cerca sul campo chiave se non lo specifici. In genere ogni mia tabella ha un campo chiave che chiamo sempre id. Ho dato per scontato che codice fosse la stessa cosa.
Colgo la palla al balzo perchè ho visto anche il metodo findByPk e non capisco come specifiare piu campi. Il mio database si compone di piu chiavi primarie per diverse tabelle. Come faccio nel mio caso ha cercare record ?
Hai delle superchiavi? Active Record è un pattern che mappa oggetti a record. Per definizione, un oggetto ha un id univoco. Non dovresti avere superchiavi. Se hai superchiavi, puoi portare il db almeno alla prima forma normale?
Errore mio: mi sembrava che la prima forma normale parlasse proprio della chiave.
Volevo dire che secondo me potresti non avere nemmeno una super chiave. Ma come mai hai solo super-chiavi? Un normale id non bastava? E’ la prima volta che sento parlare di un DB relazionato solo per super chiavi.