Comments (6)
class Content < ActiveRecord::Base
acts_as_citier
validates :page_id, presence: true
end
class CommonField < Content
acts_as_citier
self.inheritance_column = 'sub-type'
end
class Text < CommonField
end
I'm also having problems with STI. In my case, STI child class able to inherit attributes from both Content and CommonField but when i save it, Content is saving the type of STI class as nil rather than CommonField.
1.9.2p320 :006 > t = Text.new(page_id: 1)
citier -> Root Class
citier -> table_name -> contents
citier -> Non Root Class
citier -> table_name -> common_fields
citier -> tablename (view) -> view_common_fields
=> #<Text id: nil, page_id: 1, type: nil, subtype: "Text", description: nil, url: nil, created_at: nil, updated_at: nil>
1.9.2p320 :007 > t.save!
citier -> SAVING Text
citier -> Attributes for CommonField: {"id"=>nil, "page_id"=>1, "type"=>nil, "subtype"=>"Text", "description"=>nil, "url"=>nil, "created_at"=>nil, "updated_at"=>nil}
citier -> Changed attributes for CommonField: ["subtype", "page_id", "id"]
citier -> Attributes for Text: {}
citier -> Changed attributes for Text: []
citier -> SAVING CommonField
citier -> Attributes for Content: {"id"=>nil, "page_id"=>1, "type"=>nil}
citier -> Changed attributes for Content: ["page_id", "id"]
citier -> Attributes for CommonField: {"subtype"=>"Text", "description"=>nil, "url"=>nil, "created_at"=>nil, "updated_at"=>nil}
citier -> Changed attributes for CommonField: "subtype" BEGIN
SQL (0.2ms) INSERT INTOcontents
(page_id
,type
) VALUES (1, NULL)
(49.8ms) COMMIT
(0.2ms) BEGIN
SQL (0.2ms) INSERT INTOcommon_fields
(created_at
,description
,id
,subtype
,updated_at
,url
) VALUES ('2013-02-21 10:17:27', NULL, 10, 'Text', '2013-02-21 10:17:27', NULL)
(44.4ms) COMMIT
=> true
from citier.
I have exactly the same problem as @maliakmal, I had not read this post before so I started a new issue
#68. I use an ugly workaround to make the child class inherit the middle class attributes.
from citier.
This gem does not seem to be maintained, in the end i used Multiple Table Inheritance with AR.
from citier.
@zubairshams, is this a gem ? can you paste the link to it ?
from citier.
@gustavobap No i'm not using any gem, you can achieve this without the gem. But there are some gem for achieving this.
https://github.com/hzamani/acts_as_relation
https://github.com/BenjaminMedia/Heritage
But i recommend you should do this without using any gem. There is a great help to achieve Multiple table inheritance in this article.
http://techspry.com/ruby_and_rails/multiple-table-inheritance-in-rails-3/
This way you can also customize it according to your needs.
from citier.
Hi, @zubairshams thanks for the answer, I saw other solutions but they are based on simulating MTI, I want to actually inherit the model classes like with Rails STI. I ended up with a very simple workaround, in @maliakmal example the only modification would be:
class Text < CommonField
acts_as_citier :table_name => 'common_fields'
end
from citier.
Related Issues (20)
- undefined method `create_view' HOT 4
- How to use the latest Citier code? HOT 6
- item.type is deprecated HOT 1
- superclass mismatch for class SQLiteAdapter HOT 4
- Getting citier to work with SQL server
- Citier will not allow a migration for me. HOT 4
- How to suppress the citier logging HOT 1
- Unable to call destroy on Citier subtype HOT 2
- :counter_cache => true support
- relation_methods.rb delete_all strange behavior HOT 2
- View_xxx does not exist | PostgreSQL HOT 2
- Docs need some updating
- Inserting a new inherited class in the middle
- stack level too deep (when changing model inheritance)
- Two level inheritance => fetch issue HOT 1
- update_all raises ActiveRecord::StatementInvalid
- rake db:setup fails on fresh database HOT 1
- Rspec tests failing - stack level too deep error
- Two level inheritance, Child Class don't inherit Middle Class attributes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from citier.