<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Deyan Petrov</title>
    <description>The latest articles on DEV Community by Deyan Petrov (@webdeecoder).</description>
    <link>https://dev.to/webdeecoder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F880066%2F1da59ded-4e43-4d4e-9da8-e6aad886a79d.png</url>
      <title>DEV Community: Deyan Petrov</title>
      <link>https://dev.to/webdeecoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/webdeecoder"/>
    <language>en</language>
    <item>
      <title>Here is what took me an hour to sort with Prisma today.</title>
      <dc:creator>Deyan Petrov</dc:creator>
      <pubDate>Sun, 07 Aug 2022 15:41:44 +0000</pubDate>
      <link>https://dev.to/webdeecoder/here-is-what-took-me-an-hour-to-sort-with-prisma-today-38el</link>
      <guid>https://dev.to/webdeecoder/here-is-what-took-me-an-hour-to-sort-with-prisma-today-38el</guid>
      <description>&lt;p&gt;So today I started learning a bit more about Prisma using MongoDB. But I encountered and issue that seemed mind boggling.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TypeError: Cannot read properties of undefined (reading 'findMany')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLDR: Restart the server after changing Prisma Schemas.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was trying to run the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const breakTimeLog = async (req: NextApiRequest, res: NextApiResponse) =&amp;gt; {
  const tests = await prisma.breakTimeLog.findMany();
  res.status(200).json(tests);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason that it was mind boggling is that if I would replace &lt;code&gt;breakTimeLog&lt;/code&gt; with &lt;code&gt;user&lt;/code&gt; it worked fine. I tried renaming and regenerating the schema as I thought it was a naming issue due to camel case. That was the only thing I could see being different. But no luck ):&lt;/p&gt;

&lt;p&gt;Here is the Schema itself&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model User {
    id            String         @id @default(auto()) @map("_id") @db.ObjectId
    fname         String
    lname         String
    breakTimeLogs BreakTimeLog[]
}

model BreakTimeLog {
    id            String   @id @default(auto()) @map("_id") @db.ObjectId
    date          DateTime
    timeInSeconds Int
    timeOfBreak   DateTime @default(now())
    user          User     @relation(fields: [userId], references: [id])
    userId        String   @db.ObjectId
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every place I looked suggested to generate the schema again or that there is a spelling issue. After an hour on the google rabbit hole I gave up and started hacking at it with random stuff.&lt;/p&gt;

&lt;p&gt;Here is the twist I &lt;strong&gt;did not restart&lt;/strong&gt; the server after I created the new model after doing so everything is working fine!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to check if localStorage item exists</title>
      <dc:creator>Deyan Petrov</dc:creator>
      <pubDate>Sun, 07 Aug 2022 13:07:27 +0000</pubDate>
      <link>https://dev.to/webdeecoder/how-to-check-if-localstorage-item-exists-5a0m</link>
      <guid>https://dev.to/webdeecoder/how-to-check-if-localstorage-item-exists-5a0m</guid>
      <description>&lt;p&gt;Let's make this short. Since &lt;code&gt;localStorage.getItem("item")&lt;/code&gt; returns a &lt;code&gt;null&lt;/code&gt; if it is missing, we simply need to check if the return value is not &lt;code&gt;null&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (localStorage.getItem("item") !== null) {
  console.log("Item exists")
  //Do stuff
} else {
  console.log("Item does not exist")
  //Do other stuff
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
