<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;h1&gt;Extending Goldberg::User&lt;/h1&gt;
&lt;h2&gt;The Problem&lt;/h2&gt;
&lt;p&gt;Goldberg&amp;#8217;s User model comes with a basic set of fields: username, password, email, name, etc. But what if you need more fields ?&lt;/p&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;p&gt;Create a new model in your application called &amp;#8216;MyUser&amp;#8217; with all your required fields, and link it to &amp;#8216;Goldberg::User&amp;#8217;&lt;/p&gt;
&lt;p&gt;You could also modify Goldberg::User directly, but that is not recommended as you would also need to add more columns to the goldberg_users table, which could complicate upgrades. Remember, Goldberg is a plugin; don&amp;#8217;t mess with your plugin&amp;#8217;s tables.&lt;/p&gt;
&lt;h2&gt;The Code&lt;/h2&gt;
&lt;pre&gt;&lt;code&gt;# put this in your app/models/myuser.rb 
Goldberg::User.class_eval do
  has_one :myuser
end

class Myuser &amp;lt; ActiveRecord::Base
  belongs_to :user, :class_name =&amp;gt; 'Goldberg::User', :foreign_key =&amp;gt; 'goldberg_user_id'
  # other associations
  # example: has_many :posts
end&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Migration&lt;/h2&gt;
&lt;p&gt;Add a &lt;strong&gt;goldberg_user_id&lt;/strong&gt; foreign key field to &lt;strong&gt;myusers&lt;/strong&gt; table.&lt;/p&gt;
&lt;h2&gt;Loading the Associations&lt;/h2&gt;
&lt;p&gt;These associations will get loaded the first time that Rails needs to access the Myuser class; but before that Rails won&amp;#8217;t understand what #myuser means.  This could be an issue if for example you have a layout that uses &amp;#8220;Goldberg.user.myuser.some_field_name&amp;#8221;.&lt;/p&gt;
&lt;p&gt;For that reason you might want to &amp;#8220;require &amp;#8216;myuser&amp;#8217;&amp;#8221; in your RAILS_ROOT/config/environment.rb.&lt;/p&gt;</body>
  <created-at type="datetime">2008-07-11T21:09:11-07:00</created-at>
  <id type="integer">35499</id>
  <permalink>extending-goldberg-user</permalink>
  <repository-id type="integer">32863</repository-id>
  <title>Extending Goldberg::User</title>
  <updated-at type="datetime">2008-07-14T20:14:02-07:00</updated-at>
  <user-id type="integer">10853</user-id>
</wiki>
