DevHeads.net

Design patterns used in ActiveRecord Library

Hi Folks,

Just came across the question regarding what are the different design
patterns used in ActiveRecord library,

As of I know ORM is one of the design pattern used,

Is there any other design pattern used in ActiveRecord library?

Comments

Re: Design patterns used in ActiveRecord Library

By Rob Biedenharn at 06/13/2018 - 10:17

Oh, yes, there are others as you suspect. This is one of the reasons I found it incredibly difficult to implement a system in Rails using Domain Driven Design principles. I'm going to give you the answer rather than saying "This is the list for Ruby, not for Rails" since you can use ActiveRecord separately from Rails.

Active Record (PoEAA, 160) — (which is an example of a Domain Model (PoEAA, 116))
Association Table Mapping (PoEAA, 248) — has_many through (and the deprecated has_and_belongs_to_many)
Foreign Key Mapping (PoEAA, 236) — belongs_to
Identity Field (PoEAA, 216) — the ubiquitous `id`
Lazy Load (PoEAA, 200) — the behavior that can lead to 1+N issues which is overcome using eager loading
Query Object (PoEAA, 316) — technically, this is what ActiveRelation does now for ActiveRecord
Repository (PoEAA, 322) — schema and the various database adapters
Single Table Inheritance (PoEAA, 278) — for ActiveRecord subclasses using the `type` column

There are a few others that could be argued, but those are more than enough. (Either 8 or 9 depending on how you want to count Domain Model.)

"PoEAA" is Patterns of Enterprise Application Architecture, by Martin Fowler, Addison Wesley, 2003

-Rob

Re: Design patterns used in ActiveRecord Library

By vinay KP at 06/13/2018 - 10:50

Hey this helps ☺️

On Wed 13 Jun, 2018, 7:48 PM Rob Biedenharn, <rob. ... at gmail dot com>
wrote:

Re: Design patterns used in ActiveRecord Library

By Christian P at 06/13/2018 - 08:41

Hi :)

Well certainly the Active Record pattern from which it has its name.

Best Regards,

Christian

Re: Design patterns used in ActiveRecord Library

By vinay KP at 06/13/2018 - 10:16

Thank you Christian.

Is there any other design pattern used in rails ActiveRecord library !!

On Wed 13 Jun, 2018, 6:12 PM Christian P, <christian. ... at googlemail dot com>
wrote:

RE: Design patterns used in ActiveRecord Library

By Andy Jones at 06/13/2018 - 10:39

IIRC I have heard Sean Griffin (on the podcast The Bike Shed) claim that, in fact, ActiveRecord doesn’t really follow the Active Record pattern (any more?), and at this point it’s quite hard to say what pattern it does follow.

Sean is one of the maintainers of ActiveRecord, so presumably he would know…

Thank you Christian.

Is there any other design pattern used in rails ActiveRecord library !!
On Wed 13 Jun, 2018, 6:12 PM Christian P, <christian. ... at googlemail dot com<mailto:christian. ... at googlemail dot com>> wrote:
Hi :)

Well certainly the Active Record pattern from which it has its name.

Best Regards,

Christian

Am 13.06.2018 um 14:39 schrieb vinay KP < ... at gmail dot com<mailto: ... at gmail dot com>>:

Hi Folks,

Just came across the question regarding what are the different design patterns used in ActiveRecord library,

As of I know ORM is one of the design pattern used,

Is there any other design pattern used in ActiveRecord library?