Thanks for stopping by and helping me with this one. I’m trying to test models I create before continuing with the project but continue to produce an error.
What I’ve done so far was run:
mix phx.gen.context Accounts User users username:string:unique
I was wondering why I was getting the error since I alias the User schema meaning we should be able to use the property like changeset and it’s schema as well. Doesn’t the schema play a similar role to a struct? where we would be able to use %User{ username: “something” } ?
Thanks for the link as well. I’ll be taking a look at it.
Then please tell us what the exact module names of the generated context and struct are. Maybe they are namespaced by your application (this is very likely!).
Thank you! This is exactly where my lack of understanding came from. Within the file, the module name/path is
TestingLocation.Accounts.User
For some reason, I thought we didn’t need to provide TestingLocation since that was the name of the application. But when trying to us an Alias, I should use the entire path written in the module in order to gain access to it.
Thank you so much for helping me better understand this part when using alias.
Thank you so much! both you and @NobbZ. As I mentioned in a previous post, I thought we didn’t need to use our application name earlier but finally understood it is require when we want to alias it.
Thank you for that explanation in regards to MyApp being the namespace and what the appropriate way to alias a module is.
This is probably not your applications name. but your top-level “namespace”. The application name is usually a lowercased atom with snake case, probably :testing_location.
I believe the namespace was named after the application name since I used a phx generator as
mix phx.gen.context Accounts User users username:string:unique
This resulted in my module to be named as TestingLocation.Accounts.User although it sounds like we don’t need to follow such a convention of MyApp.Context.Model