Struct vs Model - Phoenix

When you generate a new Phoenix model the changeset function uses struct:

def changeset(struct...)

However in most tutorials I have seen programmers use the model approach:

def changeset(model...)

My question is, when should one use model or struct? Thanks for your time :slight_smile:

1 Like

Hi there,

Phoenix switched from model to struct in 1.2. So, the tutorials you’re reading will have been written for < 1.2.

You can see the commit here

Either will technically work because it’s just a variable name, but you should always use struct. Phoenix made the decision to move away from the model term as it implies some sort of coupling (a’la Rails) where none existed. That, and the first argument to a changeset is always a literal struct, anyway.

Hope that helps!