tattersoftware / codeigniter4-schemas

Database schema management, for CodeIgniter 4
MIT License
22 stars 10 forks source link

Can one object belongsTo more than one user ? #42

Open jozefrebjak opened 1 year ago

jozefrebjak commented 1 year ago

I have a table orders.

There is two columns disponent_id & salesman_id.

Both have foreign key to the users table id. If I don't overwrite a scheme, then it's used last one so only user paired to the salesman_id.

So I tried to overwrite schema like in https://github.com/tattersoftware/codeigniter4-schemas/issues/41. Now my relation to the users table looks like:

                [users] => Tatter\Schemas\Structures\Relation Object
                (
                    [table] => users
                    [type] => belongsTo
                    [singleton] => 
                    [pivots] => Array
                        (
                            [0] => Array
                                (
                                    [0] => orders
                                    [1] => salesman_id
                                    [2] => users
                                    [3] => id
                                )

                            [1] => Array
                                (
                                    [0] => orders
                                    [1] => disponent_id
                                    [2] => users
                                    [3] => id
                                )

                        )

                )

I think this is a bad design, but I need to pair two users from different groups because of internal settlement.

Thanks.

MGatner commented 1 year ago

This is currently a limitation of the structure, because it is based on table names. I believe there was a PR somewhere to allow aliases, which might provide a workaround.