-
-
Save shruti28/6020372 to your computer and use it in GitHub Desktop.
class Party < ActiveRecord::Base | |
attr_accessible :dateCreated, :lastUpdate, :tempForUpdate, :type | |
end | |
>>>>>>>>>> | |
class Project < Party | |
attr_accessible :country, :department, :email, :firstName, :lastName, :location, :mobilePhone, :title | |
end | |
>>>>>>>>>>>> | |
class ProjectsController < ApplicationController | |
def save | |
@project = Project.new(params[:project]) | |
@project.save | |
end | |
end | |
>>>> | |
when i am trying to save project instance,in Party type=Project is set but nothing is entered in Project table.plz help |
class Party < ActiveRecord::Base
attr_accessible :dateCreated, :lastUpdate, :tempForUpdate, :type
end
class Project < Party
attr_accessible :country, :department, :email, :firstName, :lastName, :location, :mobilePhone, :title
endclass ProjectsController < ApplicationController
def save
@project = Project.new(params[:project])
@project.save
end
endwhen i am trying to save project instance,in Party type=Project is set but nothing is entered in Project table.
When you subclass a model which has a table with a 'type' string column Rails assumes that you want to use the single table inheritance feature. Which means that all database operations for this model will occur in the inherited table; in your case it's the 'parties' table, even if the model is named differently. Rails then uses the type column with the model class name to differentiate between models.
If you want to ignore the single table inheritance for this case and force the Project model to use the projects table use the table_name method in the Project class, like this:
class Project < Party
self.table_name = "projects"
end
Read more about single table inheritance here: http://api.rubyonrails.org/classes/ActiveRecord/Base.html
If your Project model is a subclass of the Party model then it has nothing to do with the Person model. You must choose if you want to populate the 'parties' table or the 'persons' table with the new Project object data. You can't do both, unless you duplicate your save logic somewhere in your code.
Also, keep in mind that this will also cause data duplication in your database.