How to write complex queries using Propel

This is a monster subject, and I spent a long time scratching my head over a few things yesterday, until I came across this site:

http://propel.jondh.me.uk/

It’s developed by a Symfony user, and allows you to type in sql statements using nested braces for prioritising. The form will then return a nicely formatted block of Propel code.

It’s not perfect, and it doesn’t cover everything just yet, but it’s great for getting some ideas about the structure and how to use various criteria – it’s also spot on if you are trying to learn Propel and already know how to structure SQL statements.

Discuss this tool and/or contribute on the Symfony Forum

Using a combination of tools like this, and taking a look at the generated files in lib/model/om should give you a good push, and a bit of a shortcut to more complex queries than you may be used to – rather than having to trawl the Propel documentation.

Propel is complaining about a table that doesn’t exist

When you change your mind about your schema, and rename or remove any of your tables from your schema.yml or xml files, you must manually remove all the related classes in the lib/ folder.

Symfony does not delete these unused files when you run a build, so they will stack up and cause Propel errors, for example when calling propel-dump-data.

Of course you can safely delete the lib/om and lib/map folders and run the build again, but you should manually delete the relevant files in /lib as there could be some user generated content in there also. These files are unlikely to cause any errors but might as well be deleted as part of your clean up since they are effectively useless if you have removed their referenced tables from the schema.

When the pager_navigation function does not create the correct link…

If you have used a route name in the call to this function, it will be parsed based on your routing.yml file, this means that if you don’t have a :page variable listed (and you probably don’t) the route will ignore the page argument that the pager function tries to add.

The easy solution is to add /* to the end of your routing rule, so that any other parameters are allowed.

E.g.

myroute:
  url:   /somewhere/:userid/*
  param: { module: myModule, action: myAction }
 
mynextroute:
  url: etc

Now your routing functions will add any extra parameters as necessary.