您好我尝试从表中获取带有dictrine 2.5的数据,但我不知道该怎么做。
SQL FILE
DROP DATABASE composite_key;
CREATE DATABASE composite_key;
USE composite_key;
CREATE TABLE company (
id_company INT NOT NULL AUTO_INCREMENT,
name VARCHAR(200) NULL,
PRIMARY KEY (id_company)
);
CREATE TABLE users (
id_user INT NOT NULL AUTO_INCREMENT,
name VARCHAR(200) null,
PRIMARY KEY (id_user)
);
CREATE TABLE reference (
id_company INT NOT NULL,
id_user INT NOT NULL,
createat TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id_company),
FOREIGN KEY (id_company) REFERENCES company(id_company),
FOREIGN KEY (id_user) REFERENCES users(id_user)
);
INSERT INTO users (`name`) VALUES ('test1');
INSERT INTO users (`name`) VALUES ('test2');
INSERT INTO users (`name`) VALUES ('test3');
INSERT INTO company (`name`) VALUES ('company1');
INSERT INTO company (`name`) VALUES ('company2');
INSERT INTO company (`name`) VALUES ('company3');
INSERT INTO reference (`id_company`,`id_user`) VALUES (1,1);
INSERT INTO reference (`id_company`,`id_user`) VALUES (2,2);
INSERT INTO reference (`id_company`,`id_user`) VALUES (3,3);
我一直在尝试
$dql = "SELECT r FROM CompositeBundle:Reference r JOIN CompositeBundle:Company c JOIN CompositeBundle:Users u WHERE c.idCompany = 1 AND u.idUser = 1 ";
$dql = "SELECT r FROM CompositeBundle:Reference r JOIN r.idUser JOIN r.idCompany WHERE r.idCompany = 1 AND r.idUser = 1 ";
如果somone知道要做这些dql,请坐下来。