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.)

Where Next?

Popular Pragmatic Bookshelf topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
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
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
New
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New
New

Other popular topics Top

AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
AstonJ
If you want a quick and easy way to block any website on your Mac using Little Snitch simply… File > New Rule: And select Deny, O...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
DevotionGeo
I have always used antique keyboards like Cherry MX 1800 or Cherry MX 8100 and almost always have modified the switches in some way, like...
New
Fl4m3Ph03n1x
Background Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New

Sub Categories: