doctrine behaviors , if i did it like this , would be correct?
ZF
+ Doctrine 1.2.3
but i had an old database ,
it had pretty good structure so i think i can reverse engineer it with doctrine commad
./doctrine generate-models-db
,
It's amazing but I stopped when I wanted to use some doctrine behaviors l开发者_JS百科ike : searchable
as an example.
My question: if I went to my model and added these two lines :
$this->actAs('Searchable', array(
'fields' => array('title', 'content')
)
);
I am not sure if that is enough and would work as expected. If you had any more tips about creating other behaviors (like versionable
, i18n
, sluggable
or soft delete
) manually or reverse engineer it with doctrine behaviors, could you please list them?
Are you looking to reverse engineer your database and then use behaviors such as Searchable?
To start with you can generate a YAML file from the existing db schema using the "generate-yaml-db" CLI task. Thereafter you can set-up the relationships and add the necessary behaviors such as Timestampable, Searchable or you can roll out your own. Once all this is done you can generate the models using "generate-models-yaml" CLI task.
If you have added behaviors or made any changes to the schema you could generate a migration diff "generate-migrations-diff". This create the migration classes which can be used to apply the new changes made in the YAML file to the db. Run the "migrate" CLI task to apply the changes to the db.
Hope it helps.
Simply adding
$this->actAs('Searchable', array(
'fields' => array('title', 'content')
)
);
is not enough. I never used it myself but if you look at the docs, you see that it generates another table for the index.
CREATE TABLE job_index (id BIGINT,
keyword VARCHAR(200),
field VARCHAR(50),
position BIGINT,
PRIMARY KEY(id, keyword, field, position)) ENGINE = INNODB
for a model definition like
class Job extends Doctrine_Record
{
public function setUp()
{
$this->actAs('Searchable', array(
'fields' => array('title', 'content')
)
);
}
//....more methods
}
If you need heave search behavious that do more than what Doctrine can do, you should look at search on a databaes level with fulltext-searches or even external solution like Lucene (with optional Solr) Doctrine Searchable Behavior vs Zend Lucene in symfony may give you more information about that. If you have lots of data to search and need fine controll, you should look into Lucene very carefully since it will beat a pure MySQL/Doctrine solution in most cases.
精彩评论