1
I have 3 tables of funcionário
, apontamentos
and horastrabalhadas
.
My relationship is hasmany
1 employee has several apontamentos
.
When I show the result with a dd()
comes the employee data twice and the horastrabalhadas
blank. Has to invert of hasMany
for belongTo
to see if my logic was wrong but came the same thing.
Table apontamentos
CREATE TABLE IF NOT EXISTS apontamentos ( id int(10) unsigned NOT NULL
AUTO_INCREMENT, apontamento varchar(255) COLLATE utf8_unicode_ci NOT
NULL, created_at timestamp NULL DEFAULT NULL, updated_at timestamp
NULL DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT
CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
Table equipetecnicas
CREATE TABLE IF NOT EXISTS equipetecnicas ( id int(10) unsigned NOT
NULL AUTO_INCREMENT, matricula int(10) unsigned NOT NULL, nome
varchar(150) COLLATE utf8_unicode_ci NOT NULL, cargo varchar(150)
COLLATE utf8_unicode_ci DEFAULT NULL, cargahoraria int(10) unsigned
NOT NULL, nomeequipe varchar(150) COLLATE utf8_unicode_ci DEFAULT
NULL, created_at timestamp NULL DEFAULT NULL, updated_at timestamp
NULL DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT
CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3;
Table hss
CREATE TABLE IF NOT EXISTS hhs ( id int(10) unsigned NOT NULL
AUTO_INCREMENT, idequipe int(10) unsigned NOT NULL, idapontamento
int(10) unsigned NOT NULL, dataapontamento datetime NOT NULL,
horaapontamentoinicio time NOT NULL, horaapontamentofim time NOT NULL,
numeroos int(11) NOT NULL, created_at timestamp NULL DEFAULT NULL,
updated_at timestamp NULL DEFAULT NULL, PRIMARY KEY (id), KEY
hhs_idequipe_foreign (idequipe), KEY hhs_idapontamento_foreign
(idapontamento) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci
Something similar has happened to someone?
Please avoid long discussions in the comments; your talk was moved to the chat
– Maniero