hoeppner

hoeppner

From Ruby to Elixir — warning about invalid association when doing mix ecto.create (page 97)

Hi @sb8244,

I get a warning when I try to do the migrations on page 97 with mix ecto.create:

warning: invalid association sms_messages in schema PhoneApp.Conversations.Schema.Contact: associated schema PhoneApp.Conversations.Schema.SmsMessage does not have field contact_id
lib/phone_app/conversations/schema/contact.ex:1

I wanted to ask if this is because of the following:

The “SmsMessage” module has a clause that says schema "sms_messages" do. That is, the name of the module has the singular form, but the name of the schema is plural.
In case of the “Contact” module, the situation is reversed. It has an equivalent clause that says schema "contacts" do.

My confusion starts here:

The “SmsMessage” module refers to the contact s via belongs_to :contact (note the singular form in the token), while the “Contact” module refers to the SMS messages via has_many :sms_messages (note the plural).

Do the tokens’ (:contact, :sms_messages) forms (singular/plural) need to agree with the words in the schema clauses (i.e., schema "contacts" do and schema "sms_messages" do)?

Most Liked

sb8244

sb8244

Author of From Ruby to Elixir and Real-Time Phoenix

Which page are on on when you get this? One section of the chapter calls out that you’ll get a warning because we haven’t set up the other side of the association yet. In that case, the warning goes away a few pages later.

The plurality in the book is correct. Has many is plural, belongs to is singular. Schema modules are singular but the table name is plural (table name actually doesn’t matter.)

Popular Prag Prog topics Top

abtin
page 20: … protoc command… I had to additionally run the following go get commands in order to be able to compile protobuf code using go...
New
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=> (create-migration "guestbook") Execution error (Ill...
New
AleksandrKudashkin
On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1122 25133 743
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New

Latest in PragProg

View all threads ❯