Regarding the joining table values:
I think it might make sense to set one limitation, which then makes it a lot easier. Declare that a joining field cannot have a field with the same name as the fields in either of the tables it joins.
When a related model is set up, all of the extra fields in the joint table are added to a second fields array (if necessary), that I’ll call joint_fields.
This way, when the join is queried, joint fields can be added automatically to the child models (meaning, in the example above, you could access the joint fields either through $user->book->amount or through $book->user->amount (or ->all[$index]->amount). Joint fields could be added in the select statement. The developer could set the joint field in the exact same manner.
Then, when performing updates, the joint fields could be checked during _related saves, and saved into the appropriate table.
To handle the ->where(), the field is checked to see if it exists in the fields[] or joint_fields[] array, and set accordingly. Although, I actually like the join_where better than this, especially as far as work for stensi goes 😜.
Also, @ stensi, I like most of the updates (I haven’t had time to integrate them) but one problem still exists (I’m sorry!). Since the inserts still send empty fields, there is still no way (at least on PostGreSQL) to have a default, unset value. PG simply sees the field as ‘’, which errors on most field types, and ignores default field types. And since the _clear() method is called on creation of the model, any defaults set in the model are wiped out.
(Example of where this is important: I often include a field called hidden, which is used to allow the user to hide a row without deleting it. Since you never create a non-hidden value, I simply set the default to FALSE in the DB, and ignore it during inserts.)
To me, it still makes sense to filter the insert values.
- Phil DeJarnett