propel

Symfony task - memory leak

那年仲夏 提交于 2019-12-19 11:17:53
问题 I wrote a symfony task to fill a database of sample data. Here's a sample piece of code: gc_enable(); Propel::disableInstancePooling(); public function test() { for($i = 0; $i < 10000; $i++) { $this->doIt($i); } } public function doIt($i) { $user = new User(); $user->setUsername('user' . $i . "@example.com"); $user->setPassword('test'); $user->setFirstName('firstname' . $i); $user->setLastName('surname' . rand(0, 1000)); $user->save(); $user->clearAllReferences(true); $user = null; gc_collect

find query for many to many relation propel

安稳与你 提交于 2019-12-19 10:50:07
问题 i am new for propel . i face a problem to fetch all record form both table which have many to many relation . i have a user and group table. and a join table user_group. user and group have many to many relation i and using follow method to find all related data in a single query . schema.xml file <table name="user" phpName="User" idMethod="native"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" /> <column name="name" type="VARCHAR" size="100" required

Using ORM classes directly from the controller in MVC, bad practice?

我只是一个虾纸丫 提交于 2019-12-19 06:14:44
问题 I've recently delved into using an ORM in my CodeIgniter application and one i've gone for is Propel. Now this gives me the power to basically use Propels classes as the 'Model' but is this bad practive? So my controller code would be as follows: <?php class Page extends Controller { function __construct() { parent::__construct(); } function index() { $foo = FooQuery::create()->limit(10)->find(); $data['content'] = array('foo'=>$foo); $this->load->view('home', $foo); } } ?> I want to solve

Propel - Joining the same table multiple times and grouping

寵の児 提交于 2019-12-13 20:01:46
问题 I'm writing a report with Propel and need to join the same table multiple times in order to get different stats for different date ranges using the same data. The issue appears to be that propel ignores multiple ->leftJoin() calls on a query. I think I need to alias each join so they can be treated individually but I can't find a way to do that. 回答1: Try addJoin() $c = new Criteria(); $c->addJoin(array(Table1Peer::ID,), array(Table2Peer::Table1Peer_ID,), Criteria::LEFT_JOIN); Looks like you

How do I check if table names are valid in Propel?

本小妞迷上赌 提交于 2019-12-13 18:12:48
问题 I want to check if a table name is valid in Propel, and then do something with it such as get its PHP name. The problem is that I am using the DatabaseMap and it only contains tables that have been instantiated. For instance: $map = Propel::getDatabaseMap(); $map->getTableName('group'); // throws exception If I iterate over the tables: $tables = $map->getTables(); foreach ($tables as $key => $value) { echo $key; } It only outputs 'user'. It does not output any other tables in my database. Are

Get the name of all the tables on my database

↘锁芯ラ 提交于 2019-12-13 14:32:31
问题 I need get the name of all the tables that exist on my database. I am usin Propel like my ORM. Actully i have been trying on this form. $dbmap = \Propel::getDatabaseMap('data'); $tablastmp = $dbmap->getTables(); $tablas = array(); foreach ($tablastmp as $tablatmp) { $tablas[] = $tablatmp->getName(); } echo '<pre>'; print_r($tablas); echo '</pre>'; die(); but this return an array that is empty. array(); And I need that return something like that: array( [0] => 'clients', [1] => 'workers' );

Propel ORM including MAX in criteria

混江龙づ霸主 提交于 2019-12-13 13:44:22
问题 I am writing a query using the Propel ORM The query is of the form: select * from some_table where some_table.created_at = (SELECT MAX(some_table.created_at) from some_table); I got this far: $c = new Criteria(); $c->addSelectColumn('MAX('.self::CREATED_AT.')'); Anyone knows how to use Propel to do this, to save me writing RAW SQL? 回答1: Try: $c = new Criteria(); $c->add(SomeTable::CREATED_AT, '(SELECT MAX('.SomeTable::CREATED_AT.') FROM some_table)', Criteria::CUSTOM); 回答2: If you jhust want

Propel migration with multiple connections defined

一笑奈何 提交于 2019-12-13 03:06:14
问题 Is there any chance I can migrate only one database, if I have define multiple connections in my config.yml If I run propel:migration:diff --connection=a it still want to generate migration for all databases defined. My vendors propel/propel-bundle 1.2.7 Integration of Propel in Symfony2 propel/propel1 1.6.9 Propel is an open-source Object-Relational Mapping (ORM) for PHP5. 回答1: Yes, you can. Although I have Propel 1.7.1 I don't think this has changed since 1.6.9 . You have to create a

Propel and leftJoin

自作多情 提交于 2019-12-12 12:08:36
问题 In Doctrine i can: $q = Doctrine_Query::create() ->from('One o') ->where('t.text = ?', 'aaa') ->andWhere('h.text = ?', 'bbb') ->leftJoin('o.Two t') ->leftJoin('t.Three h') ->leftJoin('h.Four f') ->execute(); How can i make this in Propel from Symfony 1? 回答1: If you use propel before 1.6 , you have to follow You have to know the primary key for each relation. If it's id , it can be something like that: $c = new Criteria(); $c->add(TwoPeer::TEXT, 'aaa'); $c->add(ThreePeer::TEXT, 'bbb'); $c-

How do I make Propel retain associative format with singular selects?

纵然是瞬间 提交于 2019-12-12 06:30:35
问题 I have the following Criteria in Propel: $q = \UserQuery::create(); $q->select(array('id', 'name')); $q->orderBy('name'); $q->setOffset($offset); $q->setLimit($limit); return $q->find(); This works fine, and gives me a two-dimensional array with id and name keys in the inner array, i.e. array( array("id" => 1, "name" => 'A'), array("id" => 2, "name" => 'B') ) However, if I run the following: $q = \UserQuery::create(); $q->select(array('id')); $q->orderBy('id'); $q->setOffset($offset); $q-