-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
206 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class CreateVisits extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* Write your reversible migrations using this method. | ||
* | ||
* More information on writing migrations is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class | ||
* | ||
* The following commands can be used in this method and Phinx will | ||
* automatically reverse them when rolling back: | ||
* | ||
* createTable | ||
* renameTable | ||
* addColumn | ||
* renameColumn | ||
* addIndex | ||
* addForeignKey | ||
* | ||
* Remember to call "create()" or "update()" and NOT "save()" when working | ||
* with the Table class. | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->table('visits'); | ||
$table->addColumn('user_id', 'integer', [ | ||
'default' => null, | ||
'limit' => 11, | ||
'null' => false, | ||
]); | ||
$table->addColumn('created', 'datetime', [ | ||
'default' => null, | ||
'null' => false, | ||
]); | ||
$table->create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
namespace App\Model\Entity; | ||
|
||
use Cake\ORM\Entity; | ||
|
||
/** | ||
* Visit Entity. | ||
* | ||
* @property int $id | ||
* @property int $user_id | ||
* @property \App\Model\Entity\User $user | ||
* @property \Cake\I18n\Time $created | ||
*/ | ||
class Visit extends Entity | ||
{ | ||
|
||
/** | ||
* Fields that can be mass assigned using newEntity() or patchEntity(). | ||
* | ||
* Note that when '*' is set to true, this allows all unspecified fields to | ||
* be mass assigned. For security purposes, it is advised to set '*' to false | ||
* (or remove it), and explicitly make individual fields accessible as needed. | ||
* | ||
* @var array | ||
*/ | ||
protected $_accessible = [ | ||
'*' => true, | ||
'id' => false, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
namespace App\Model\Table; | ||
|
||
use App\Model\Entity\Visit; | ||
use Cake\ORM\Query; | ||
use Cake\ORM\RulesChecker; | ||
use Cake\ORM\Table; | ||
use Cake\Validation\Validator; | ||
|
||
/** | ||
* Visits Model | ||
* | ||
* @property \Cake\ORM\Association\BelongsTo $Users | ||
*/ | ||
class VisitsTable extends Table | ||
{ | ||
|
||
/** | ||
* Initialize method | ||
* | ||
* @param array $config The configuration for the Table. | ||
* @return void | ||
*/ | ||
public function initialize(array $config) | ||
{ | ||
parent::initialize($config); | ||
|
||
$this->table('visits'); | ||
$this->displayField('id'); | ||
$this->primaryKey('id'); | ||
|
||
$this->addBehavior('Timestamp'); | ||
|
||
$this->belongsTo('Users', [ | ||
'foreignKey' => 'user_id', | ||
'joinType' => 'INNER' | ||
]); | ||
} | ||
|
||
/** | ||
* Default validation rules. | ||
* | ||
* @param \Cake\Validation\Validator $validator Validator instance. | ||
* @return \Cake\Validation\Validator | ||
*/ | ||
public function validationDefault(Validator $validator) | ||
{ | ||
$validator | ||
->integer('id') | ||
->allowEmpty('id', 'create'); | ||
|
||
return $validator; | ||
} | ||
|
||
/** | ||
* Returns a rules checker object that will be used for validating | ||
* application integrity. | ||
* | ||
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. | ||
* @return \Cake\ORM\RulesChecker | ||
*/ | ||
public function buildRules(RulesChecker $rules) | ||
{ | ||
$rules->add($rules->existsIn(['user_id'], 'Users')); | ||
return $rules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace App\Test\Fixture; | ||
|
||
use Cake\TestSuite\Fixture\TestFixture; | ||
|
||
/** | ||
* VisitsFixture | ||
* | ||
*/ | ||
class VisitsFixture extends TestFixture | ||
{ | ||
|
||
/** | ||
* Fields | ||
* | ||
* @var array | ||
*/ | ||
// @codingStandardsIgnoreStart | ||
public $fields = [ | ||
'id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], | ||
'user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], | ||
'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], | ||
'_constraints' => [ | ||
'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], | ||
], | ||
'_options' => [ | ||
'engine' => 'InnoDB', | ||
'collation' => 'utf8_general_ci' | ||
], | ||
]; | ||
// @codingStandardsIgnoreEnd | ||
|
||
/** | ||
* Records | ||
* | ||
* @var array | ||
*/ | ||
public $records = [ | ||
[ | ||
'id' => 1, | ||
'user_id' => 1, | ||
'created' => '2016-02-15 15:01:28' | ||
], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters