Skip to content

Instantly share code, notes, and snippets.

@IdahoEv
Created May 22, 2015 22:20
Show Gist options
  • Save IdahoEv/e88c24d2cd22ba258f39 to your computer and use it in GitHub Desktop.
Save IdahoEv/e88c24d2cd22ba258f39 to your computer and use it in GitHub Desktop.
Weird mismatch in columns
#app/models/profile.rb
module Profile
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def adopter
User.find_by(email: self.adopter_email).profile
end
end
def serializer_class
nil
end
end
# checking in psql, it seems that schema.rb is right and ActiveRecord is wrong.
mindswarms_web_dev=# \d researchers
Table "public.researchers"
Column | Type | Modifiers
-----------------+------------------------+----------------------------------------------------------
id | integer | not null default nextval('researchers_id_seq'::regclass)
company | character varying(255) |
status | integer |
organization_id | integer |
#it's not a very complex AR model
#app/models/profile/researcher.rb
require 'profile'
class Profile::Researcher < ActiveRecord::Base
include Profile
has_one :user, as: :profile
belongs_to :organization
has_many :videos, as: :owner
has_many :owned_surveys, as: :owner, class_name: 'Survey'
validates_presence_of :organization
def self.adopter_email
'adopter@researcher.com'
end
def serializer_class
ResearcherSerializer
end
end
# The schema disagrees with console about the column names
create_table "researchers", force: true do |t|
t.string "company"
t.integer "status"
t.integer "organization_id"
end
(byebug) Profile::Researcher.table_name
"researchers"
(byebug) Profile::Researcher.column_names
["id", "first_name", "last_name", "company", "status", "user_id"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment