Created
May 22, 2015 22:20
-
-
Save IdahoEv/e88c24d2cd22ba258f39 to your computer and use it in GitHub Desktop.
Weird mismatch in columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
'[email protected]' | |
end | |
def serializer_class | |
ResearcherSerializer | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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