Menu
  • HOME
  • TAGS

Rails: Circular dependency in connected STI classes

ruby-on-rails,ruby,rails-activerecord,single-table-inheritance

Category and Meter both reference each other in their class definitions, so neither can load without the other being loaded first. If you put the class_name in quotes you should be good: has_many :children, class_name: 'Meter', ... My spidey sense is a little tingly, though, with your domain model. You...

Factory Girl tries to access a table that does not exist when using Single Table Inheritance

ruby-on-rails,single-table-inheritance

The problem was self.abstract_class=true in the Event parent class. I totally forgot that an abstract class in rails is something completely different from languages like C# or Java. Or as the official website puts it: abstract_class Set this to true if this is an abstract class (see abstract_class?). If you...

How to use @UniqueConstraint with single table inheritance (JPA)?

java,hibernate,jpa,unique-constraint,single-table-inheritance

You cannot override the base class @Table declaration, that's why the sub-class uniqueConstraints directive is ignored. With JPA you can override annotations with xml declarations. So you need to add an orm.xml file in your class-pat and add the unique constraints there: <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd" version="2.0"> <package>...</package> <entity...

EF inheritance with TPT - how to specify the foreign key column name?

entity-framework,single-table-inheritance

Figured it out. First, in order to debug this, it was helpful to see the actual mapping that EF creates behind the scenes. I installed the EF Power Tools VS extension, r-clicked the context file, Entity Framework -> View Entity Data Model and got this: Notice the entity Employee has...

Using a private method with Single Table Inheritance

ruby-on-rails,ruby,single-table-inheritance,private-methods

def save_users_access_time current_user.update_last_seen_at end You can't call a private method outside the user class it self, that's why you have an issue, you could change that method to a normal public method Regardless of that, I actually think the whole method is unnecessary, if all that it's going to do...

Doctrine Single Table Inheritance and bidirectional OneToMany: columns not being generated

doctrine2,doctrine,one-to-many,single-table-inheritance,bidirectional

You do not need to have a "collars" column on the pet table. It is a one-to-many relationship, so the only table that need to "know" about pets are the collar table. A bidirectional relationship does not mean you need two columns on two tables. Your map seems correct....

Java SingleTable inheritance in db structure using JPA/Hibernate

java,hibernate,jpa,single-table-inheritance

In JPA you can't redefine your inheritance strategy down the inheritance tree, the root definition of the inheritance sets it for the whole inheritance tree

Rails STI: How to change mapping between class name & value of the 'type' column

ruby-on-rails,types,single-table-inheritance,sti

You can try something like this: class Proyect < ActiveRecord::Base end Then the Indoor class but with Other name class Other < Proyect class << self def find_sti_class(type_name) type_name = self.name super end def sti_name "Indoor" end end end The same apply for Outdoor class. You can check sti_name in...

Rails - How to create the right kind of object from Single Table Inheritance?

ruby-on-rails,single-table-inheritance

First of all, I think you do not need set_user_type method because you are not using the @user_type variable that its setting. Take out before_action from top of the controller as well. Second, in user_type method you need to change params[:type] to params[:user_type] since that's the name of radio button...

Multiple level of different kind of inheritance

php,doctrine2,multiple-inheritance,single-table-inheritance

As @OCramius said in a comment to my question, this is not supported by Doctrine ORM. So to do what I wanted to do, I will store a value object in the data property of my object, storing the property of "child classes" instead of having deep different kind of...

rails validate uniqueness within inheritance

ruby-on-rails,validation,single-table-inheritance

If anybody is having the same problem here is how I solved it validate :uniqueness_within_category def uniqueness_within_category first_category_type = (Tag.find_by(category: self.category).nil?)? 'none' : Tag.find_by(category: self.category)._type if first_category_type == 'none' #It doesnt exist then should be allowed return end #If it exists within another class type then shouldnt be allowed if...

Single Table Inheritance with Factory Girl in Rails

ruby-on-rails,rspec,factory-girl,single-table-inheritance

Change: let(:video_collection) do FactoryGirl.create(:video_collection) end to: let!(:video_collection) do FactoryGirl.create(:video_collection) end ...

Rails STI vs Polymorphic vs Neither

ruby-on-rails,polymorphism,polymorphic-associations,single-table-inheritance,sti

STI can work for this, but since the difference between the types of users is basically a flag that says a user is an admin, you just need something on a user to check whether they are allowed certain actions. Roles can be either exclusive or inclusive (so that a...

Rails models with Single Table Inheritance and HABTM

ruby-on-rails,ruby,relationships,single-table-inheritance

Try to add one additional model GameTeam and make has_many :through relation class GameTeam belongs_to :game belongs_to :team validates :team_type, presence: true end class Game has_many :game_teams has_may :teams, through: :game_teams end Then you can make game.teams to fetch all teams. You can additionally implement scopes of methods to get...

Single Table Inheritance or Polymorphic?

ruby-on-rails,ruby,activerecord,polymorphism,single-table-inheritance

As Rails only supports STI out of the box, if you really want MTI, you can give the ActiveRecord::ActsAs gem a shot. There are a couple of open issues in their tracker but development seems to be somewhat active....

Single Table Inheritance with btn-group on create form

ruby-on-rails,forms,ruby-on-rails-4,form-for,single-table-inheritance

I am not sure about the authentication, but instead of using additional classes for public and private, you could just create a type field that tells you whether or not the project is public or private something like is_public. The other option is to use a enum release in rails...