<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Intelligrape  Groovy &#38; Grails Blogs &#187; load</title>
	<atom:link href="http://www.intelligrape.com/blog/tag/load/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.intelligrape.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 07:48:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
			<title>Intelligrape  Groovy &amp; Grails Blogs</title>
			<url>http://www.intelligrape.com/blog/wp-content/uploads/2011/05/favicon2.ico</url>
			<link>http://www.intelligrape.com/blog</link>
			<width></width>
			<height></height>
			<description></description>
		</image>		<item>
		<title>Grails : load proxy domain objects</title>
		<link>http://www.intelligrape.com/blog/2010/07/26/grails-load-proxy-domain-objects/</link>
		<comments>http://www.intelligrape.com/blog/2010/07/26/grails-load-proxy-domain-objects/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 12:44:30 +0000</pubDate>
		<dc:creator>Amit Jain</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://www.intelligrape.com/blog/?p=1394</guid>
		<description><![CDATA[Hi Friends,
I was going through grails docs, encountered a method called load(), found it really useful thought would share with you. What load() does is, it creates a proxy object and doesn&#8217;t retrieve the record from the database until property other than id is accessed.
Let us consider a scenario, where we have id of a [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Friends,</p>
<p>I was going through grails docs, encountered a method called load(), found it really useful thought would share with you. What load() does is, it creates a proxy object and doesn&#8217;t retrieve the record from the database until property other than id is accessed.<br />
Let us consider a scenario, where we have id of a Object &#8220;subject&#8221; and students of that subject needs to be listed. So we would generally do something like as given below:</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="groovy">Subject subject <span style="color: #66cc66;">=</span> Subject.<span style="color: #663399;">get</span><span style="color: #66cc66;">&#40;</span>subjectId<span style="color: #66cc66;">&#41;</span>
Student.<span style="color: #006600;">findBySubject</span><span style="color: #66cc66;">&#40;</span>subject<span style="color: #66cc66;">&#41;</span></pre></div></div>

</div>
<p>In the above code, we had to load subject unnecessarily where its &#8216;id&#8217; should have been sufficient. Now, with load no extra queries are required.</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="groovy">Subject subject <span style="color: #66cc66;">=</span> Subject.<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span>subjectId<span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">//creates a proxy object, not retrieved from database </span>
Student.<span style="color: #006600;">findBySubject</span><span style="color: #66cc66;">&#40;</span>subject<span style="color: #66cc66;">&#41;</span></pre></div></div>

</div>
<p>And same when used with criteria queries</p>
<div class="code">

<div class="wp_syntax"><div class="code"><pre class="groovy">Student.<span style="color: #006600;">list</span><span style="color: #66cc66;">&#123;</span>
  eq<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'subject'</span>, Subject.<span style="color: #006600;">load</span><span style="color: #66cc66;">&#40;</span>subjectId<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  ...
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</div>
<p>Thanks to the grails development team for all their efforts!</p>
<p>Cheers!!</p>
<p>~~Amit Jain~~<br />
amit@intelligrape.com</p>
<p>http://www.IntelliGrape.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.intelligrape.com/blog/2010/07/26/grails-load-proxy-domain-objects/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

