MushroomObserver / mushroom-observer

A website for sharing observations of mushrooms.
https://mushroomobserver.org
MIT License
78 stars 25 forks source link

Non-db backed Model for INat::Obs #2432

Open JoeCohen opened 2 weeks ago

JoeCohen commented 2 weeks ago

Refactor Inat::Obs to use a non-db backed model with attribute accessors instead of a Hash lookup.

andrew nimmo Sep 28, 2024, 1:58 PM (14 hours ago) Joe - I believe there is a better, more standard Railsy way to do all this, and there's an example on my PR: Define your inat_obs as an activemodel object. This gives you the accessor methods without repetitive declarations, and other goodies besides. You won't have to access by hash key. It's a "model not backed by a db table" and it's a very convenient thing.

Example PR #2337

nimmolo commented 2 weeks ago

One thing to be aware of: when defining your models, you will need a line defining the attributes, because they can't be inferred from db columns.

attributes: :this, :that, :the_other

On my model, i'm doing this by iterating through some params defined elsewhere, but you'll probably want to write the list explicitly.

From there, you can just write instance methods and class methods the usual way. There seem to be so few gotchas, it's relaxing!

JoeCohen commented 2 weeks ago

thanks again. i’ll give it a try on tues

Sent from Gmail Mobile

El El dom, sept 29, 2024 a la(s) 04:54, andrew nimmo < @.***> escribió:

One thing to be aware of: when defining your models, you will need a line defining the attributes, because they can't be inferred from db columns.

attributes: :this, :that, :the_other

On my model, i'm doing this by iterating through some params defined elsewhere, but you'll probably want to write the list explicitly.

From there, you can just write instance methods and class methods the usual way. There seem to be so few gotchas, it's relaxing!

— Reply to this email directly, view it on GitHub https://github.com/MushroomObserver/mushroom-observer/issues/2432#issuecomment-2381327216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALDFFQOULTXO3WE4F7PTTZY7TABAVCNFSM6AAAAABPBULYR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBRGMZDOMRRGY . You are receiving this because you were assigned.Message ID: @.***>