DEV Community

lughjw
lughjw

Posted on

ActiveRecord: Some Quick Tips

The rules:
Base classes are memory objects
Migration classes are what's stored in the database
They only exist in conjunction because of ActiveRecord magic

A short and sweet background on ActiveRecord concepts. ActiveRecord::Base classes hold the object representation that will be held in memory. ActiveRecord::Migration classes hold how the object is represented in the database. Understanding these things is what finally made me stop wanting to throw my laptop across the room when using ActiveRecord.

Any time you have something that you don't care if it gets lost when you save it, store it in a base file. If you don't want to lose it when it's restored then make sure there's a variable for it in the database.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay