Propel3
Propel3 copied to clipboard
No ->save() function generated by propel build?
Hi, I'm relatively new to Propel. I setup my DB with propel init
, and did propel build
, which generated the models. However, when I tried to use the ->save()
function, my IDE reports that the method does not exist. Does anyone know why this is so?
I'm using PHPStorm 2017.1.4
Also, my IDE also reports that another definition with the same name exists in the file, and commenting out the use myNameSpace\SubNameSpace\ModelName
seemed to help.
bump
In Propel3 active-record methods are optional. Set activeRecord="true"
at <entity>
or <database>
to activate it.
What if I don't activate it? What is the difference? And if I don't enable it, how do I persist objects to the database.
In the data mapper pattern, the persistance logic is not contained into the entity, so you should use the session objectd to do it:
// create the $configuration manually
$configuration = new Configuration(‘./path/to/propel.yml’);
$session = $configuration->createSession();
$car1 = new Car(‘Ford Mustang’);
$session->persist($car);
$car2 = new Car(‘Ferrari Testarossa’);
$session->persist($car);
$session->commit(); //Save the objects to the database, following the unit-of-work pattern