Propel update query




















With a single SQL query, you can have both a list of objects and an additional column for each object. That makes of withColumn a great query saver. After writing custom methods to query objects, developers often meet the need to use the method from another query. For instance, in order to select the authors of the most recent books, you may want to write:. The problem is that recent is a method of BookQuery , not of the AuthorQuery class that the create factory returns. Does that mean that you must repeat the BookQuery::recent code into a new AuthorQuery::recentBooks method?

That would imply repeating the same code in two classes, which is not a good practice. This is exactly what the generated useBookQuery does, except that you have more control over the join type and alias when you use the relational API. Behind the scene, useQuery 'Book' creates a BookQuery instance and returns it. So the recent call is actually called on BookQuery , not on ArticleQuery.

So the final find is indeed called on the AuthorQuery instance. You can nest queries in as many levels as you like, in order to avoid the repetition of code in your model. Tip If you define an alias for the relation in join , you must pass this alias instead of the model name in useQuery. SQL supports table subqueries a. For instance, to find the latest book written by every author in SQL, it usually takes a query like the following:.

Thanks to the query factories and the fluid interface, developers can query the database without creating a variable for the Query object. This helps a lot to reduce the amount of code necessary to write a query, and it also makes the code more readable. But when you need to call a method on a Query object only if a certain condition is satisfied, it becomes compulsory to use a variable for the Query object:.

The ModelCriteria class offers a neat way to keep your code to a minimum in such occasions. Using theses methods, the previous query can be written as follows:. The Propel Query objects have even more methods that allow you to write queries of any level of complexity. Usually the formatter defines which collection will be returned, but Propel gives you a nitty-gritty trick to overwrite that behavior.

For performance reasons, you may want to get a collection of arrays instead. Use the setFormatter to specify a custom result formatter. Of course, the formatters take the calls to with into account, so you can end up with a precise array representation of a model object:. Some internal methods were also renamed to fit PSR coding standards. Due to the supporting of PHP 7. Many thanks to contributors! Instead of directly extending the PHP core classes, we now depend on interface contracts.

If your software has directly extended those in the past, please make sure to adjust your extensions accordingly. With this release, we continue Alpha-version cleanups aiming API stabilization. Many thanks to our contributors, who made possible this release to come that fast. It's a good target for project updates, as it has the widest dependency list including EOL components. In the following releases, we expect to reduce the support of EOL components.

With this small release, we start a series of upgrades and stabilization activities of Propel2, which aim to end with the following stable 2. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Migrations Change the structure of the database without altering the data.

Compatibility index A list of primary limitations regarding different databases. Configuration file Complete list of Propel configuration properties. Behaviors Reference Writing A Behavior How to write a custom behavior to reuse model code horizontally.



0コメント

  • 1000 / 1000