<?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: Mahendra Choudhary</title>
    <description>The latest articles on DEV Community by Mahendra Choudhary (@mahendrachoudhary).</description>
    <link>https://dev.to/mahendrachoudhary</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%2F196089%2F8561c137-0d8b-43e3-b0a6-433abefbe298.png</url>
      <title>DEV Community: Mahendra Choudhary</title>
      <link>https://dev.to/mahendrachoudhary</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mahendrachoudhary"/>
    <language>en</language>
    <item>
      <title>Need help with sql (*_*) !</title>
      <dc:creator>Mahendra Choudhary</dc:creator>
      <pubDate>Wed, 18 Sep 2019 14:23:25 +0000</pubDate>
      <link>https://dev.to/mahendrachoudhary/need-help-with-sql--14i5</link>
      <guid>https://dev.to/mahendrachoudhary/need-help-with-sql--14i5</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4sojhADE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/n4os6b57lr6yzipw5d8n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4sojhADE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/n4os6b57lr6yzipw5d8n.png" alt="Alt Text" width="880" height="495"&gt;&lt;/a&gt;&lt;br&gt;
hi dev's &lt;/p&gt;

&lt;p&gt;While working on a "hospital management system" demo project using rails.I stucked in a scenario where I need to pull "firstname" from users table. Here is detailed scenario ...&lt;/p&gt;

&lt;p&gt;So Here are my tables :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;table1 : appointments has following columns 
         id|patient_id|physician_id|
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;table2: patients table                  table3: physicians table
         id|user_id|...                      id|user_id|...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;table4: users (note that users table as 4 types of user admim,patient,physician and nurse )&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      id|firstname|lastname|role|.....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;** Here user_id refers to users table primary key &lt;br&gt;
** patient_id and physician_id refers to patients and physicians primary key&lt;/p&gt;

&lt;p&gt;Now how can i fetch "firstname" from users table from appointments table???? &lt;/p&gt;

&lt;p&gt;As of now i am using following code to print appointments but this is to costly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# frozen_string_literal: true&lt;/span&gt;

&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Admin&lt;/span&gt;
  &lt;span class="c1"&gt;# Appointment actions&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppointmentsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
    &lt;span class="n"&gt;before_action&lt;/span&gt; &lt;span class="ss"&gt;:new_user&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
      &lt;span class="vi"&gt;@appointments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;paginate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fetch_records&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;respond_to&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
        &lt;span class="nb"&gt;format&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="vi"&gt;@appointments&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

   &lt;span class="p"&gt;.&lt;/span&gt;
   &lt;span class="nf"&gt;.&lt;/span&gt;
   &lt;span class="p"&gt;.&lt;/span&gt;

    &lt;span class="nf"&gt;private&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_records&lt;/span&gt;
      &lt;span class="vi"&gt;@appointments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;admin?&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="no"&gt;Appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="no"&gt;Appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;physician&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="vi"&gt;@appointments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;appointment&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="n"&gt;appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;patient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;physician&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firstname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="n"&gt;appointment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appointment_date&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;rails --versin  : rails 5.2.3&lt;br&gt;
ruby --version: 2.6.3&lt;/p&gt;

</description>
      <category>help</category>
      <category>database</category>
      <category>sql</category>
      <category>rails</category>
    </item>
    <item>
      <title>Short bit and byte</title>
      <dc:creator>Mahendra Choudhary</dc:creator>
      <pubDate>Tue, 20 Aug 2019 05:52:48 +0000</pubDate>
      <link>https://dev.to/mahendrachoudhary/short-bit-and-byte-27j9</link>
      <guid>https://dev.to/mahendrachoudhary/short-bit-and-byte-27j9</guid>
      <description>&lt;p&gt;While scrolling down to my LinkedIn feeds this morning I found this short story (&lt;em&gt;_&lt;/em&gt;) which summarizes lessons from all the success stories  . So I just want to share with all my fellow devs .&lt;/p&gt;

&lt;p&gt;2 stories to begin with &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Nokia refused Android &lt;/li&gt;
&lt;li&gt;Yahoo refused Google &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Story over &lt;/p&gt;

&lt;p&gt;Lessons learnt &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Take risks &lt;/li&gt;
&lt;li&gt;Embrace changes &lt;/li&gt;
&lt;li&gt;If you refuse to change with time , you might perish &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ok 2 more stories &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Facebook takes over whatsapp and instagram &lt;/li&gt;
&lt;li&gt;Flipkart takes over myntra and flipkart owned Myntra takes over jabong &amp;amp; now Flipkart is taken over by Walmart &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Story over &lt;/p&gt;

&lt;p&gt;Lessons learnt &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Become so powerful that your competitors become your allies .&lt;/li&gt;
&lt;li&gt;Reach the top position and then eliminate the competition&lt;/li&gt;
&lt;li&gt;keep innovating &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2 more stories &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Colonel sanders founded KFC at the age of 65 .&lt;/li&gt;
&lt;li&gt;Jack Ma , who coudnt get job in kfc , founded ALibaba .&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;story over &lt;/p&gt;

&lt;p&gt;Lesson learnt &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Age is just a number .&lt;/li&gt;
&lt;li&gt;Only those who keep trying succeeds .&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Last but not least &lt;/p&gt;

&lt;p&gt;1.Lamborghini was founded as result of revenge of a tractor owner who was insulted by Enzy Ferrari , the founder of ferrari&lt;/p&gt;

&lt;p&gt;Story over&lt;/p&gt;

&lt;p&gt;Lessons learnt &lt;br&gt;
1.Never underestimate anyone , ever !! .&lt;br&gt;
2.Success is the best revenge .&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>php</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Things to know in rails?which help me to be a better rails developer</title>
      <dc:creator>Mahendra Choudhary</dc:creator>
      <pubDate>Wed, 24 Jul 2019 05:13:16 +0000</pubDate>
      <link>https://dev.to/mahendrachoudhary/things-to-know-in-rails-which-help-me-to-be-a-better-rails-developer-53nd</link>
      <guid>https://dev.to/mahendrachoudhary/things-to-know-in-rails-which-help-me-to-be-a-better-rails-developer-53nd</guid>
      <description>&lt;p&gt;I started out as a junior rails developer a month ago .I like to ask senior devs what tips you like to give to beginner . What things should I learn which will help me in future ? &lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
