-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres Table Inheritance Support #4313
Comments
The problem is in the |
Hey Pixeltrix Been playing around with this again and noticed that adding
Do you see any problems with doing this, or if support for this will ever be rolled into Rails proper? |
I've checked it on both master and 3-2-stable and it works correctly. @robertsosinski let me know if this is still an issue for you. |
Just to add for posterity, I had this same issue when using "acts_as_nested_set" and MY fix was not to put in the self.columns_hash ['id'] line, but to do this in my parent class: parent #...
self.abstract_class = true
def self.inherited(base)
base.acts_as_nested_set
end
#... child class ChildThing < ParentThing
end worked fine for me! |
Unfortunately, neither of these solutions worked for me on a Rails 3.2.17. For my needs I ended up sorting the array in memory after pulling from the DB.
|
Hello,
It seems certain operations (finding by id, inserting, updating) has issues when using table inheritance. For example, I have the following three tables:
All operations work correctly on the
trades
table, but for thestock_trades
andbond_trades
table, things get a bit finicky with theid
field. I can doStockTrade.where(:id => 1)
, orStockTrade.find_by_id(1)
. However, if I doStockTrade.find(1)
, the query fails with the following:You'll notice that it is not referencing the id in the where clause (being just an empty set of quotes).
Creating new records on
stock_trades
orbond_trades
also yields a problem with theid
. Creating a new stock trade withStockTrade.create(:price => '33.33'.to_d, :quantity => 100, :ticker => 'VZ')
for example, fails with the following:The issue seems to be that Postgres trying to write to the
id
with anull
, instead of leaving it out of the values list.Updating also has problems as well. Doing
st = StockTrade.find_by_id(1); st.update_attribute(:quantity, 101)
fails with the following:Overall, it seems that ActiveRecord is not seeing the
id
column, or is not identifying it as an id.The text was updated successfully, but these errors were encountered: