<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - STI, Polymorphic Inheritance or other?]]></title>
		<link>http://railsforum.com/viewtopic.php?id=52332</link>
		<description><![CDATA[The most recent posts in STI, Polymorphic Inheritance or other?.]]></description>
		<lastBuildDate>Sun, 03 Feb 2013 14:29:39 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[STI, Polymorphic Inheritance or other?]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=158803#p158803</link>
			<description><![CDATA[<p>Hi all,</p><p>I&#039;m planning an application at the moment for my property management business.</p><p>I&#039;m looking to develop the tool to manage rentals/lettings of properties but may looking to allow the tool to be used by friends running their own companies too.</p><p>So my users are:</p><p>Employees (those who work with me)<br />They have different types: Manager, Agent, Accounting Staff, Administration Staff/Secretaries etc.</p><p>Landlords (those who own properties)<br />Will log in to see information about the properties I&#039;m managing for them</p><p>Tenants (those who rent properties)<br />Will log in to see information about the property they live in (i.e. move in date, contracts etc).</p><p>What is the best way of modelling this?</p><p>I already have a User model/class/table built with all my authentication/authorisation code and I&#039;m trying to be DRY. So I think it&#039;s overkill to re-do this code for each user.</p><p>I was thinking of having Employee, Landlord and Tenant as subclasses of User (maybe use polymorphic association - not sure if its the best approach). Also I&#039;d have STI and use the type field on the Employee model to signify which type of staff is logging in and using the system.</p><p>Further to this I also have a Property model. At present Properties belong to a User (the user_id is the foreign key in the Property table). I was thinking &quot;what happens if an employee leaves and we delete their ID?)</p><p>So maybe it&#039;s better to say the Property belongs to a Company. Where the company is that which the current user belongs to. Is this a good approach?</p><p>Properties also belong to Landlords or should I be thinking of the Landlords belonging to the Property?</p><p>I just want to make sure that I build following best practises and build a tool that will grow with my business as well as cater for others.</p><p>Many thanks for taking the time to read and I look forward to your thoughts <img src="http://railsforum.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Oh and I&#039;ve outlined this problem on stackoverflow, perhaps with a bit more detail and some pseudo code here: <a href="http://stackoverflow.com/questions/14661456/modelling-an-application-in-rails-mixing-sti-and-polymorphic-associations">http://stackoverflow.com/questions/1466 &#133; sociations</a></p>]]></description>
			<author><![CDATA[dummy@example.com (chigzy)]]></author>
			<pubDate>Sun, 03 Feb 2013 14:29:39 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=158803#p158803</guid>
		</item>
	</channel>
</rss>
