开发者

How do you setup relationships with many foreign keys from the same table in PHP ActiveRecord?

开发者 https://www.devze.com 2023-04-09 16:59 出处:网络
I am building a real es开发者_Go百科tate related website that real estate agents and investors can use to track properties submitted in the system and keep track of who is owed what profits. I have th

I am building a real es开发者_Go百科tate related website that real estate agents and investors can use to track properties submitted in the system and keep track of who is owed what profits. I have the following tables that I am having trouble figuring out how to setup the relationships for in my models using PHP ActiveRecord:

properties

  • id
  • primary_profit_sharing
  • secondary_profit_sharing
  • commission
  • referral_payment

users

  • id
  • name
  • email

payments

  • id
  • type (commission, referral_payment, etc.)
  • property_id
  • user_id

What is the proper way to setup these relationships using PHP ActiveRecord? I would like to be able to access the user information for each payment by something like $property->commission and $property->referral_payment but I can't figure out how to setup the relationships in the models to allow that.

I currently have payments belonging to users and properties, and users/payments have many payments. All the information I was is returned in the query, but not in an accessible ways. I have $property->users but no way of getting the user information for a particular payment type.

The only way I can think of to accomplish what I'm looking for is to setup a table for each payment type, but that doesn't seem like the best way to do it.


In the payments table, instead of using property_id and user_id, maybe you should use fk_object as the foreign key and do your joins using that field. fk_object represents the id of the user or the id of the property.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号