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 Pragmatic Bookshelf topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
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
telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
Mmm
Hi, build fails on: bracket-lib = “~0.8.1” when running on Mac Mini M1 Rust version 1.5.0: Compiling winit v0.22.2 error[E0308]: mi...
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
Exadra37
Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it. Does your monitor have eye p...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
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
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New