-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preferences hidden option? #2
Comments
Thanks! I'm glad you like it!
That's a good idea. I was going to get back into this library pretty soon to add preference caching. I may do hidden preferences at the same time. There may be other Eloquent features to move into the library too. I'll dig around for 'em.
Depending on how fancy your RDBMS is you might be able to add an class User extends Eloquent
{
use HasPreferences;
// ...
public static function boot()
{
parent::boot();
User::deleting(function (User $user) {
// Delete a user's preferences before deleting the user.
$user->preferences()->delete();
});
}
} Notes and disclaimers about data loss from deleting things and testing code that deletes before copy/pasting this directly into production. :) Hope this helps! |
Awesome. I didn't want to muck around with the Cascading too much as I'd end up forgetting, it's much easier to trace through code ;) Your function worked well after I figured out that deleting never get's called on a bulk delete.
won't call it.
works fine... although not as tidy as I'd like ;) |
Sucks that Eloquent won't call events on a bulk delete, but I guess that's what cascading on the database end is for. Looping through users to delete takes slightly longer and isn't as efficient, but so long as it works that's the important thing. :) I just realized that the library has a small helper that can at least make the deleting/deleted event a little simpler. Call Since this looks like it's been answered I'm going to close this issue. I'll add support for hiding columns when I get a spare moment or two. Thanks again! |
Add support for hiding preference attributes from JSON export by defining hidden attributes in either the config file or the MODEL_PREFERENCE_HIDDEN_ATTRIBUTES constant. See issue #2 for the feature request.
Great library here, so easy!
One suggestions from myself:
Have a $hidden array as well as the "casts" and "defaults" so we can set it to not return created_at etc. fields? They're adding unnecessary bloat to my returning JSON as I just grab all preferences attached to the user.
Secondly, and unrelated... is there a way to do a cascading delete? So when I delete my model, all the prefs are deleted as well? So if I have a Department, with a hasMany relationship to Users that have preferences, I could go $department->users()->delete() as I do now, but have the prefs for the users get nuked as well?
The text was updated successfully, but these errors were encountered: