Reputation: 141
i created a new model in rails with the following commands:
rails g model prod_domain name:string type:string user_logon_name:string description:string email:string address:string company:string department:string dn:string sa_description:string is_sa:string sa_remap_description:string ownership:string comment:text
rake db:migrate
i added some function in the model like this:
class ProdDomain < ActiveRecord::Base
def self.search_by_id(keyword)
users = Array.new
ProdDomain.where(id: keyword).find_each do |user|
users.push(user)
end
return users
end
def self.search(keyword)
users = []
ProdDomain.where(dn: keyword).find_each do |user|
users.push(user)
end
users
end
end
however, when i try to find records in this model, i kept getting 'USER' class instead of 'ProdDomain' class, what am i doing wrong:
(byebug) ProdDomain.find(1).class
ProdDomain Load (0.4ms) SELECT
prod_domains
.* FROMprod_domains
WHEREprod_domains
.id
= 1 LIMIT 1
User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, created_at: datetime, updated_at: datetime, username: string, role: integer, dn: string, department: string, name: string)
Upvotes: 0
Views: 142
Reputation: 168
It looks like you have a type
column defined. In Rails the type
column is used by default for indicating inheritance.
If you're not intending on using inheritance then you can rename the column (something like kind
is common) or you can overwrite the column name that Rails will use Base.inheritance_column
.
Upvotes: 0