About how to use activerow ref

Notice: This thread is very old.
alnux
Member | 139
+
0
-

Hi im trying to use ref method and it works with the first way

$author = $book->ref('author', 'author_id'); // this works perfect

but i cant make run it directly, I mean with the foreing key reference. in my case

$permissions =  $this->model->all();
foreach ($permisssions as $permission)
{
    echo $permission->ref('fk_acl_permisos_acl_roles_1')->name;  // it does not work
    echo $permission->fk_acl_permisos_acl_roles_1->name;  //neither works
}

next my tables

acl_permisos table

CREATE TABLE IF NOT EXISTS `acl_permisos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `role_id` int(11) NOT NULL,
  `privilege_id` int(11) DEFAULT NULL,
  `resource_id` int(11) DEFAULT NULL,
  `access` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `role_id_index` (`role_id`),
  KEY `privilege_id_index` (`privilege_id`),
  KEY `resource_id_index` (`resource_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;


ALTER TABLE `acl_permisos`
ADD CONSTRAINT `fk_acl_permisos_acl_roles_1` FOREIGN KEY (`role_id`) REFERENCES `acl_roles` (`id`);

acl_roles table

CREATE TABLE IF NOT EXISTS `acl_roles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_id` int(11) DEFAULT NULL,
  `key_name` varchar(64) NOT NULL,
  `name` varchar(64) NOT NULL,
  `comment` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `key_name_unico` (`key_name`),
  UNIQUE KEY `name_unico` (`name`),
  KEY `parent_id_index` (`parent_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

Or maybe im doing it in a bad way!!!!!

Caine
Member | 216
+
0
-

It wont work with names of constrains, you must use the connecting column:

$permission->ref('acl_roles'[, 'role_id'])->name; //if you dont specify the column it will try to look up one in constrains
// or via key
$permission->role->name; // this tries to find any matching column which in this case would be role_id

Anyway dont use NDBT, because sooner or later caching problem will catch you or you hit the wall as soon as you will be in need of using e.g. conditions in joins or any other more complex queries..

alnux
Member | 139
+
0
-

Caine wrote:

It wont work with names of constrains, you must use the connecting column:

$permission->ref('acl_roles'[, 'role_id'])->name; //if you dont specify the column it will try to look up one in constrains
// or via key
$permission->role->name; // this tries to find any matching column which in this case would be role_id

Anyway dont use NDBT, because sooner or later caching problem will catch you or you hit the wall as soon as you will be in need of using e.g. conditions in joins or any other more complex queries..

Hi caine first thanks for the answear and i was viewing your profile and you have an alternative to NDBT, flunorette … tell me? does it have this feature (ref key)??? becouse it is really useful on templates

regards

Caine
Member | 216
+
0
-

Flunorette is meant to be as in place replacement for NDBT2.0 with much more freedom (full control over the sql inside Selection) and without still (over 2/3 years) buggy column caching. There is a bit more – see wiki, anyway it has only MySql driver yet.

PS: I made it because i hit the wall with NDBT and since it was easier to create my own implementation than to switch to a different db layer with all our projects..

alnux
Member | 139
+
0
-

Caine wrote:

Flunorette is meant to be as in place replacement for NDBT2.0 with much more freedom (full control over the sql inside Selection) and without still (over 2/3 years) buggy column caching. There is a bit more – see wiki, anyway it has only MySql driver yet.

PS: I made it because i hit the wall with NDBT and since it was easier to create my own implementation than to switch to a different db layer with all our projects..

Hi caine i want to use your extension but i cant find the composer required option, could you send me the url where is in. and how can i call from services im refering to the namespace that i have to call just like nette context

function __construct(\Nette\Database\Context $db)// instead this flunorette namespace

and the flunorette extension config.neon declaration

thanks

Last edited by alnux (2014-07-07 19:02)

Caine
Member | 216
+
0
-

Extension is here: https://github.com/…xtension.php

Can be used in neon config:

extensions:
	flunorette: Flunorette\Bridges\Nette\FlunoretteExtension

flunorette:
    default:
        dsn:        "mysql:host=127.0.0.1;dbname=test"
        user:       "root"
        password:   "password"
        options:    [PDO::MYSQL_ATTR_COMPRESS = true]
        debugger:   true        # debugger bar panel
        explain:    true        # explain queries in debugger bar
        reflection: discovered  # or conventional or classname, default is discovered
        autowired:  true
    anotherConnection:
        dsn: ...
        autowired: false

$context->getService('flunorette.default')

alnux
Member | 139
+
0
-

Thanks Caine, but you forgot the composer required package option to download by composer.
Regards

Caine
Member | 216
+
0
-

its icaine/flunorette.. i forgot to add it to readme.

alnux
Member | 139
+
0
-

Caine wrote:

its icaine/flunorette.. i forgot to add it to readme.

i think specifically

"icaine/flunorette": "dev-master"

isnt it?

Caine
Member | 216
+
0
-

“icaine/flunorette”: “~1.0”