php - Two tables in Laravel are related through multiple fields. How to write the model relationship?
漂亮男人
漂亮男人 2017-05-27 17:43:51
0
1
765

For example, table A has x_id, y_id, and table B also has x_id, y_id. The two fields in table A are 1 to multiple B tables.

select XXX from A left join B on A.x_id = B.x_id and A.y_id = B.y_id

There are belongsTo and belongsToMany in laravel. Finding relevant documents may not be able to meet my needs. The key is that there is an And relationship here.

漂亮男人
漂亮男人

reply all(1)
刘奇

Redesign the database table structure. Add an auto-incrementing primary key to table A. The x_id and y_id in table A are jointly unique, UNIQUE KEY A_x_id_y_id_UNIQUE (x_id, y_id). Then joining is easy.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template