I have a relation table of objects_users and i want to add a group field onto each row to tell me what level of access a user has related to object. Is there a way to set this group value upon linking to the two objects together?
$object = new Object();
$object->users[] = $current_user // somehow set group = 50 or something during this assign or save process
$object->save();
The ORM doesn't support extra columns in the relationship or through table.
You can work around that by defining a model for the relationship table, and define the relationship as:
modelB -> has_one <=> has_many model_through -> has_many <=> has_one modelB
Thanks. Do you think it would be a hairy/complex task to extend ORM to handle additional data. Is that even useful? The fact I need to do this kind of makes me think that I'm implementing something in a sub-optimal way.
How would you go about implementing a layer of permissions on a set of objects where users own or are part of the object and can only enact certain functions based on their permissions on those objects? I was going to put a check in the before() on the controller level, but that also did not seem optimal. Another idea was maybe an Auth::instance('object') might be a good method with ACls for the object specifically, but then that seemed like overkill.
During some debugging I found that a many_many relationship actually has a property 'model_through' which seems to be null by default. I've not looked into it at all yet, but it seems like perhaps you could (or maybe the intent is to) set a class name on the model_through property to use it to add extra data.