A blur of smiles

This was taken in the late seventies — I was born in 1971, my sister three years later. I was maybe six, she, three. It wasn’t printed until 2004, according to the back of the print. It’s a bit…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Active Record joins Methods

The joins method is a convinient way to combine two tables that are associated with each other. The best way to demonstrate this is through an example. Let’s say that we have two tables, one is a table of roles and another is a table of auditions. The association between roles and auditions is one to many.

Let’s fill the tables with data.

In your terminal, type the following:

This will be the virtual table.

The virtual table shown above has the two tables combined. Let’s break this down step by step.

Look at the console below.

It only returns the Roles portion of the virtual table. If you flip the tables, you get:

So underneath it all, the tables are combined but you will only get the attributes of the one you specified.

Now you’re asking, if I’m only getting only one table out of this, why would this be useful? Let’s say your boss wants you to give him an array of instances of roles that have been hired. Looking at the table above, the roles of Tatyana and Shela are filled. To get this answer, you simply have to type:

I added the distinct there because otherwise, two instances with the character name of “Tatyana” would show up. The line above would get this:

You see that the output is an array with the filled roles. Let’s decipher the code.

If your boss asks you to give him instances of actors that tried out for the roles of characters with less than 6 letters (weird request, but you gotta get that money). You type this.

and BAM, you got your three audtions that tried out for the role of Shela and Isela, characters with names less than 6 letters.

Add a comment

Related posts:

About CardWallet

The payment industry has come a long way in the past couple of years. With the advent of blockchain-based transactions, there has been a huge revolution in this industry as cashless/digital payments…

Emoji Is a Mistake

Mixing images with letters was a terrible idea. One may object that emoji are widely adopted and used by a vast amount of people. But the correlation between quantity of usage and quality of idea…

Eagles sign four of their nine 2021 draft picks

The Philadelphia Eagles agreed to terms on rookie contracts with four of their nine draft picks from the 2021 NFL Draft on Thursday. The four who signed are first-round pick WR Devonta Smith…