Question: I'm trying to make a left join select and use AND to compare a column against a specific value, i.e. a condition.

The problem is I don't know where to add the condition. The below medoo query returns the first shirt id of the same user id even if all 'is\_wearing\_shirt' set to 0. A regular mysql query however returns the expected data.

Here's the medoo query:

```
$db->select('users', array(
    '[>]shirts' => array(
        'user_id' => 'shirt_owner_id',
        'is_wearing_shirt' => 1 // equivalent to AND is_wearing_shirt = 1
    )
), array(
    'user_id',
    'shirt_id(shirt_id_being_worn)'
) , array(
    'user_id' => 1,
    'LIMIT' => 1
));
// always returns a shirt_id (even if all rows have is_wearing_shirt set to 0, in which case, shirt_id should be null)

```

Here's the regular MySQL query that works:

```
SELECT u.user_id, s.shirt_id
FROM  `cvs_users` u
LEFT JOIN `shirts` s
    ON user_id = shirt_owner_id
    AND shirt_being_worn = 1
WHERE user_id = 1
//returns the correct shirt_id

```

Answer: 
As Amadan implies, you will have to change the active item through DOM manipulation (ie JavaScript). If you want the first item to be the initial active one:

```
<div class="carousel-inner">
    <% @post.gallery_images.each.with_index do |img, index| %>
    <% if index == 0 %>
    <div class="item active">
    <% else %>
    <div class="item">
    <% end %>
       <%= image_tag img.image.url, class: 'img-responsive' %>
    </div>
    <% end %>
</div>

```

There are, of course, more elegant solutions than this. But this is just go give you some quick help.
Although Rails will seem like the popular option, you can easily do this with JavaScript.

Add the following code (either line) to the bottom on your template.

```
<script type="text/javascript">
/* add 'active' class to the first item */
$('.carousel-inner .item').first().addClass('active');

/* add 'active' class to the last item */
$('.carousel-inner .item').last().addClass('active');
</script>

```