I have the following tables:
user
, logbook
, user_logbook
User logbook is a junction table (isCrossRef="true"
in the schema.xml), containing user_id
and logbook_id
foreign keys.
I also wanted to remember the currently selected logbook for any given user, so I put a current_logbook_id
in my user
table also, and gave that a foreign key. However, in my BaseUserQuery.php
file I get two filterByLogbook()
functions.
I know that when you have two foreign keys to the same table, from the same table, you get functions like getUserRelatedBySomething()
and getUserRelatedBySomethingElse()
, but what is the best thing to do in this situation?
I can of course just remove the foreign key and just use the ID saved, or I suppose I could create a new junction table (though that doesn't seem correct). What is the best thing to do in this situation, in terms of "doing the right thing" in MySQL and Propel (hopefully I'll be able to do both!).
In your schema.xml
add phpName and refPhpName attributes to the foreign key in the user table definition:
<table name="user" phpName="User">
...
<foreign-key foreignTable="logbook" phpName="CurrentLogBook" refPhpName="CurrentLogBookUser">
<reference local="current_logbook_id" foreign="id"/>
</foreign-key>
...
</table>
Then you should get filterByCurrentLogBook()
and filterByCurrentLogBookUser()
functions and no collisions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With