brunnofoggia/doctrine-dashes

This is an additional active record pack for DBAL Integration. It will provide all is needed to connect with a database, read and persist relational data quick and easy.

1.12.0 2019-11-25 17:40 UTC

This package is auto-updated.

Last update: 2024-11-26 04:38:55 UTC


README

Minimum PHP Version License

This is an additional active record pack for DBAL Integration. It will provide all is needed to connect with a database, read and persist relational data quick and easy

Version notice

This works for DBAL ^2.5

What this plugin provides?

Features for Model

  • Persist methods - save, update, create, delete, deleteAll
  • Retrieve methods - get, find, exists
  • Persist related data methods - saveBelongsTo, saveHasMany, saveHasAndBelongsToMany
  • Retrieve related data methods - getRelated, getBelongsTo, getHasMany, getHasAndBelongsToMany
  • Properties available for customization: table, primaryKey, foreignKeys[], fieldsFormat[], recursive

Installation

You should install this with composer. Read the VCS repo docs. A initial composer.json would looks like:

{
  "require": {
      "doctrine/dbal": "^2.5",
      "brunnofoggia/doctrine-dashes": "@dev"
  }
}

Usage

  1. Import it into classes that will use it

    class Sample_model {

     use \doctrine\Dashes\Model;
     protected $table = 'sample';
    

    }

  2. Get an instance of the model

    2.1. Setting connection config before

     \Sample_model::setConnConfig('default', [
         'host' => 'localhost',
         'user' => 'root',
         'pass' => '123',
         'dbname' => 'test'
     ]);
     $test = new Sample_model;
    

    2.2. Sending connection config

     $test = new Sample_model([
         'host' => 'localhost',
         'user' => 'root',
         'pass' => '123',
         'dbname' => 'test'
     ]);
    
  3. try to read a record

     $pk = 1;
     $test->get($pk);
    

Detailed documentation