<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Part 3 &#8211; Flex Cairngorm/WebORB Issue Tracker Tutorial &#8211; Using ActiveRecord Associations with WebORB</title>
	<atom:link href="http://flexonrails.net/?feed=rss2&#038;p=51" rel="self" type="application/rss+xml" />
	<link>http://flexonrails.net/?p=51</link>
	<description>-</description>
	<lastBuildDate>Tue, 22 Dec 2009 16:08:15 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Derek Wischusen</title>
		<link>http://flexonrails.net/?p=51&#038;cpage=1#comment-15327</link>
		<dc:creator>Derek Wischusen</dc:creator>
		<pubDate>Sat, 28 Apr 2007 04:59:41 +0000</pubDate>
		<guid isPermaLink="false">http://flexonrails.net/?p=51#comment-15327</guid>
		<description>Hi Michael,


I think that maybe your post got cut off.  Either try to re-post or just send me an email at dwischus [at] flexonrails [dot] net.

Derek</description>
		<content:encoded><![CDATA[<p>Hi Michael,</p>
<p>I think that maybe your post got cut off.  Either try to re-post or just send me an email at dwischus [at] flexonrails [dot] net.</p>
<p>Derek</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://flexonrails.net/?p=51&#038;cpage=1#comment-15123</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Fri, 27 Apr 2007 17:27:29 +0000</pubDate>
		<guid isPermaLink="false">http://flexonrails.net/?p=51#comment-15123</guid>
		<description>Please Help!!!
I am having trouble with the has_and_belongs_to_many association with WebOrb.  

*** The Actors ***

Sql Tables
----------
table people
 id: int auto-increment pk
 name: varchar

table groups
 id: int auto-increment pk
 name: varchar

table groups_people
 group_id: int pk
 person_id: int pk


Ruby Model Classes
------------------
class Person </description>
		<content:encoded><![CDATA[<p>Please Help!!!<br />
I am having trouble with the has_and_belongs_to_many association with WebOrb.  </p>
<p>*** The Actors ***</p>
<p>Sql Tables<br />
&#8212;&#8212;&#8212;-<br />
table people<br />
 id: int auto-increment pk<br />
 name: varchar</p>
<p>table groups<br />
 id: int auto-increment pk<br />
 name: varchar</p>
<p>table groups_people<br />
 group_id: int pk<br />
 person_id: int pk</p>
<p>Ruby Model Classes<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
class Person</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel</title>
		<link>http://flexonrails.net/?p=51&#038;cpage=1#comment-13507</link>
		<dc:creator>Joel</dc:creator>
		<pubDate>Thu, 19 Apr 2007 15:06:08 +0000</pubDate>
		<guid isPermaLink="false">http://flexonrails.net/?p=51#comment-13507</guid>
		<description>If both of my VOs represent database tables, what fills in the values of the Books_Users table on the Rails side? Would there be a bit of code in the addUser service method, for example? 

Cheers,

Joel</description>
		<content:encoded><![CDATA[<p>If both of my VOs represent database tables, what fills in the values of the Books_Users table on the Rails side? Would there be a bit of code in the addUser service method, for example? </p>
<p>Cheers,</p>
<p>Joel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Derek Wischusen</title>
		<link>http://flexonrails.net/?p=51&#038;cpage=1#comment-13491</link>
		<dc:creator>Derek Wischusen</dc:creator>
		<pubDate>Thu, 19 Apr 2007 04:48:12 +0000</pubDate>
		<guid isPermaLink="false">http://flexonrails.net/?p=51#comment-13491</guid>
		<description>Hi Joel,

The model (ActiveRecord) knows which issue belongs to which user because that is the info that is stored in the join table.

So if you have,

class Book &lt; ActiveRecord::Base
  has_and_belongs_to_many :users
end

and

class User &lt; ActiveRecord::Base
  has_and_belongs_to_many :books
end


then following the Rails convention for join tables (i.e., classes1_classes2) you will have a table in your database called,

books_users

books_users has two columns,

book_id
user_id

Ok, so now if you do the following,
@user = User.find(:first)
@books = @user.books

when you call @user.books Rails figures out a whole lot of things based on convention.  First it checks the id of User model instance that was returned by User.find(:first).  Then it looks for a table called books_users and finds all of the ones where the user_id value matches the id of the current user.  Then it grabs the the value stored in book_id for each of these.  Lastly, it searches through the books table for books whose id are in the list of book_ids and returns these as Book model instances to @books.  See all of the hard work that ActiveRecord is doing for you?

Derek</description>
		<content:encoded><![CDATA[<p>Hi Joel,</p>
<p>The model (ActiveRecord) knows which issue belongs to which user because that is the info that is stored in the join table.</p>
<p>So if you have,</p>
<p>class Book < ActiveRecord::Base<br />
  has_and_belongs_to_many :users<br />
end</p>
<p>and</p>
<p>class User < ActiveRecord::Base<br />
  has_and_belongs_to_many :books<br />
end</p>
<p>then following the Rails convention for join tables (i.e., classes1_classes2) you will have a table in your database called,</p>
<p>books_users</p>
<p>books_users has two columns,</p>
<p>book_id<br />
user_id</p>
<p>Ok, so now if you do the following,<br />
@user = User.find(:first)<br />
@books = @user.books</p>
<p>when you call @user.books Rails figures out a whole lot of things based on convention.  First it checks the id of User model instance that was returned by User.find(:first).  Then it looks for a table called books_users and finds all of the ones where the user_id value matches the id of the current user.  Then it grabs the the value stored in book_id for each of these.  Lastly, it searches through the books table for books whose id are in the list of book_ids and returns these as Book model instances to @books.  See all of the hard work that ActiveRecord is doing for you?</p>
<p>Derek</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joel</title>
		<link>http://flexonrails.net/?p=51&#038;cpage=1#comment-13460</link>
		<dc:creator>Joel</dc:creator>
		<pubDate>Wed, 18 Apr 2007 18:35:15 +0000</pubDate>
		<guid isPermaLink="false">http://flexonrails.net/?p=51#comment-13460</guid>
		<description>@Derek - I appreciate your time and effort in explaining this to me. The model makes sense. How does the model know which issue belongs to which user?

In my case I am making a book library and sharing application. A user (UserVO) enters a book (BookVO). I have corresponding tables for each. Of course, lots of users might own a single book, so I don&#039;t want multiple entries for twins. Initially I have put a User_ID field in each BookVO, but this locks the book to the user that first input the book. So without a join table in the middle keeping track of these relationships, I just can&#039;t wrap my brain around it.</description>
		<content:encoded><![CDATA[<p>@Derek &#8211; I appreciate your time and effort in explaining this to me. The model makes sense. How does the model know which issue belongs to which user?</p>
<p>In my case I am making a book library and sharing application. A user (UserVO) enters a book (BookVO). I have corresponding tables for each. Of course, lots of users might own a single book, so I don&#8217;t want multiple entries for twins. Initially I have put a User_ID field in each BookVO, but this locks the book to the user that first input the book. So without a join table in the middle keeping track of these relationships, I just can&#8217;t wrap my brain around it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
