i have two models, one is Robots, another is RobotsTypes. Robots has a 1-1 relationship with RobotsTypes.
CREATE TABLE robots (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(70) NOT NULL,
type_id int(3) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE robots_types (
type_id int(3) unsigned NOT NULL AUTO_INCREMENT,
type_name int(10) NOT NULL,
PRIMARY KEY (type_id),
);
i want $robots has typeName attribute, so i did this
$robots = Robots::find();
$robots = $robots->filter(
function ($robot) {
$robot->typeName = $robot->RobotsTypes->typeName ;
return $robot;
}
);
but it doesn't work. why? is there another simple way to do this?