<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - scope requires join and present condition]]></title>
		<link>http://railsforum.com/viewtopic.php?id=51842</link>
		<description><![CDATA[The most recent posts in scope requires join and present condition.]]></description>
		<lastBuildDate>Thu, 03 Jan 2013 22:50:58 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[scope requires join and present condition]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=158017#p158017</link>
			<description><![CDATA[<p>Let&#039;s say my model looks like this</p><p>&nbsp; &nbsp;* Guest<br />&nbsp; &nbsp;* Ride (n:m)<br />&nbsp; &nbsp;* Taxi</p><p>The rides have time_from/time_to attributes, so the association between Guest and Taxi is valid within a time frame. <strong>Now I want to create a scope in Guest that selects me only those guests that are currently riding in a taxi</strong>, which means that guest.taxi.present? = true ...but only if Time.zone.now is between ride.time_from and ride.time_to (or Time.zone.now is &gt;= ride.time_from and ride.time_to is null).<br />I think I can go the hard way and write a long SQL statement that does 2 joins manually. But since I&#039;ve defined the relationship already (guest has_many taxis, :through =&gt; :ride), I think there must be a better way... could you help me please?</p>]]></description>
			<author><![CDATA[dummy@example.com (thorstenhirsch)]]></author>
			<pubDate>Thu, 03 Jan 2013 22:50:58 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=158017#p158017</guid>
		</item>
	</channel>
</rss>
