ActiveAndroid icon indicating copy to clipboard operation
ActiveAndroid copied to clipboard

Add all() and first() convenience methods and make save() overridable

Open tacoman667 opened this issue 10 years ago • 9 comments

Added convenience method for first() and all(). changed save() from final to overridable. Sometimes one might want to be able to wrap the save command with additional functionality, like logging, or creation of new relationship objects, etc.

tacoman667 avatar Oct 20 '15 18:10 tacoman667

Sounds useful, though I've wondered for a while what were the motivations behind making these methods final. I wish they weren't final so that I could add beforeSave and afterSave callbacks on a few models (perhaps annotated with @CallSuper?).

saulojg avatar Oct 20 '15 18:10 saulojg

Forgive me if I am not completely up to speed on Java. I am more versed in C#, Ruby, JavaScript, etc. Does @CallSuper annotation make all overrides fail the compile step if the overridden method doesn't call super.overriddenMethod()?

Personally, I override save() on a few of my models so that I can add event logging for a business application. This was my motivation to open save() back up again and remove that final declaration.

tacoman667 avatar Oct 20 '15 20:10 tacoman667

@tacoman667 Hey, I like your additions. Any idea how I would easily include your fork? I'm used to npm and RubyGems right now so can't figure out this .jar and Maven stuff.

joshuapinter avatar Mar 08 '17 04:03 joshuapinter

@joshuapinter Unfortunately, you will have to build the jar or include the source into your project and reference it locally. That's what I did for my Android project. Our fork is at https://github.com/surgeforward/ActiveAndroid with these small changes in this PR or you can just add the few lines of code to your own fork.

tacoman667 avatar Mar 08 '17 12:03 tacoman667

@tacoman667 Thanks for the response. Yeah, I figured it's not as easy as updating the GitHub branch on a package.json file. :)

I had trouble building the .jar, likely because the Gradle build tools and config are so out of date so I'll try referencing the local project and see how that goes. Thanks.

joshuapinter avatar Mar 08 '17 14:03 joshuapinter

@tacoman667 Just an update, include the library and have everything working great, including your updates and some other things, like returning the saved object on save() instead of the object's id. Plus, now I can make super quick updates to the library without leaving my project and having to generate a .jar file. Definitely the way to go.

joshuapinter avatar Mar 08 '17 15:03 joshuapinter

@joshuapinter Glad I could help! Sad that this project seems dead though. :(

TBH, I am more into RealmDB on mobile devices these days...

tacoman667 avatar Mar 08 '17 15:03 tacoman667

@tacoman667 Me too, actually. I use Realm (and their sync platform) for my side project, ntwrk. Cross platform, React Native with built-in sync. It's not perfect but it's pretty damn good and getting better all the time. Plus, no need for a ORM, its native methods are good enough.

We're still heavily engrained with ActiveAndroid on my work's mobile app and, to be fair, it's been great. However, will eventually migrate over to Realm as we convert things to React Native and consolidate our platform support.

joshuapinter avatar Mar 08 '17 15:03 joshuapinter

@joshuapinter @tacoman667 take a look at https://jitpack.io/, it'll let you use your forks in your projects with minimal hassle

saulojg avatar May 05 '17 18:05 saulojg