I lately started to use Propel (PHP ORM) and I love it but I have one quite annoying issue I can't resolve even with a lot of trying. I use reverse engineering to create my schema.xml, which works great until it comes to joins. Sadly for all my foreign keys the reverse engineering only adds the name
and not the phpName
attribute. Whatever I try to use this name
attribute for a join I fail. After I added the phpName
attribute manually (and then rebuilding the models of course) the join works fine as it should.
Here is the snippet of the foreign key in the schema.xml (without the phpName attribute obviously):
<foreign-key foreignTable="users" name="messages_ibfk_1">
<reference local="creating_user_id" foreign="id"/>
</foreign-key>
And here is the code for my join (which doesn't work):
$messages = MessagesQuery::create()->joinWith('messages_ibfk_1')->findByRecipientId($id);
I tried all kinds of variations for the joinWith
value but none worked. On top of the schema this setting is active: defaultPhpNamingMethod="underscore"
The error propel pulls out is: Unknown relation messages_ibfk_1 on the Messages table.
If I add the phpName
attribut with the value Author
the join works fine like that:
$messages = MessagesQuery::create()->joinWith('Author')->findByRecipientId($id);
As I have a lot of foreign keys and I want minimum/none manual work the question is: How do I resolve this without adding all the phpName
attributes manually. Either I find a way to access the foreign keys with their regular name attribute or there is a way to tell propel to set up the phpName
attribute while building the models?
I hope someone has an idea, would be a great help! :)