开发者

Propel ORM data fixtures

开发者 https://www.devze.com 2023-01-21 05:12 出处:网络
If I开发者_如何学C have a yml data fixture file called mydata.yml User: anonymous: nickname: anonymous

If I开发者_如何学C have a yml data fixture file called mydata.yml

User:
  anonymous:
    nickname: anonymous
    first_name: Anonymous

  david:
    nickname: david
    first_name: David

How do I tell propel where to find this file. Do I need to add any instructions to the build.properties

and how do I run it to insert the data into the database (I've already done propel-gen insert-sql, do I need to repeat it or something)

Note: I'm using Propel in a php project not a Symfony project so don't have access to any settings Symfony may have added if any.


You can prepare your inserts in a separate SQL file (for example fixtures.sql) and tell the Propel in file sqldb.map to run it when processing the propel-gen insert-sql command.

Contents of the sqldb.map may look like this:

# Sqlfile -> Database map
schema.sql=yourdatabasename
fixtures.sql=yourdatabasename

The sqldb.map file is created in directory specified by propel.sql.dir line in build.properties file.

In theory you can run Symfony sandbox somewhere and let it convert the fixtures in yml format to SQL commands and then use it with Propel in your project.


Loading data from fixtures is a feature that Symfony adds to Propel, it is not a part of the "core" Propel framework. So if you don't use Symfony, you can't load the data without other code. It might be possible to isolate and strip out the code from the sfPropelData class that does the actual loading, so you can use it in another framework. Please release your code to the public if you succeed in this, others might like it too!

0

精彩评论

暂无评论...
验证码 换一张
取 消