Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Couple things going on here I see so far: </p> <p>type is a reserved word in Rails. It is used for single table inheritance. If you change your column name to something like "post_type" it should help immensely in trying to solve random issues. I went through this a while back and was beating my brains out before I knew about STI. </p> <p>Also, you have a type_id in your post . . . but I didn't see that your post <code>:belongs_to :type</code> . . . don't forget that a model with the foreign key needs this declaration to use all the ActiveRecord associations. </p> <p>Hope this helps!</p> <p>Another Edit: I noticed that in your insert statement, it appears you have a "type" column? This will also cause issues when using relationships. Are you using a separate 'type' model? Can you possibly post your schema if any of the above statements don't help? </p> <p>In ActiveRecord, a type column is reserved and will not display properly(back to my statement about Single Table Inheritance). At this point I strongly recommend getting rid of your type and type_id columns, and giving your Post a "<code>post_type_id</code>" column. </p> <p>Then once you create a separate <code>post_type</code> model that <code>has_many :posts</code> you will want to make sure your <code>Post :belongs_to :post_type</code> (because it has the foreign key). Once you do that, you will be able to call <code>post_object.post_type</code> and it will return the model relationship you are looking for. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload