Dont work has one retation

Notice: This thread is very old.
FromRussia
Member | 7
+
0
-

Hi! i am use ActiveRow

$clients = $this->database->table('clients');
        foreach($clients as $client){
            dump($client);
            dump($client->ref('clients_enterpneur', 'id_client'));
            echo '<hr>';
        }

have error

No reference found for $clients->ref(clients_enterpneur)

use has many, it work

$clients = $this->database->table('clients');


foreach($clients as $client){
    dump($client);
    foreach($client->related('clients_enterpneur.id_client') as $item){
        dump($item);
    }
    echo '<hr>';
}

DB
clients
CREATE TABLE IF NOT EXISTS clients (
id int(11) NOT NULL,
legal_type varchar(1) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

clients_enterpneur
CREATE TABLE IF NOT EXISTS clients_enterpneur (
id_client int(11) NOT NULL,
name varchar(45) DEFAULT NULL,
person_first_name varchar(45) DEFAULT NULL,
person_last_name varchar(45) DEFAULT NULL,
ICO decimal(10,0) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

what is the problem?

Oli
Member | 1215
+
0
-

Hi, i'm not sure, but i gues it's because id_client. In nette world is convention name foreign key like name of the foreign table + _id. So, try change id_client to client_id.

I think, it can be changed somewhere in config, but i never tried it.

CZechBoY
Member | 3608
+
0
-

Use method related, because you use 1:M relation… if you want 1:1 the foreign column should be in clients table (id_clients_enterpneu).

FromRussia
Member | 7
+
0
-

CZechBoY wrote:

Use method related, because you use 1:M relation… if you want 1:1 the foreign column should be in clients table (id_clients_enterpneu).

Thank you! I'm sorry that is not the topic.
Someone knows the plug-in to connect AcriveRecord Nette?

FromRussia
Member | 7
+
0
-

Or is there a way to set the ratio
from ‘tablename’ ⇒ ‘field’ to ‘tablename’ ⇒ ‘filed’

FromRussia
Member | 7
+
0
-

Active Record for Dibi

https://github.com/…ctive-record

CZechBoY
Member | 3608
+
0
-

You can use dibi instead of Nette\Database of course.