On Monday, 14 July 2014 16:30:03 UTC-4, Ruby-Forum.com User wrote:
>
> Hi Matt, 
>
> Schema looks like this. 
>
> sqlite> .schema transaction_items 
> CREATE TABLE "transaction_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT 
> NOT NULL, "transaction_type_id" integer, "note" varchar(255), 
> "transaction_date" datetime, "created_at" datetime, "updated_at" 
> datetime); 
>
> sqlite> .schema transaction_types 
> CREATE TABLE "transaction_types" ("id" INTEGER PRIMARY KEY AUTOINCREMENT 
> NOT NULL, "name" varchar(255), "tran_type" varchar(255), "created_at" 
> datetime, "updated_at" datetime); 
>
> There is no specific table for expense_type and income_type. 
> transaction_types table's tran_type column decides whether it is a 
> income / expense type. 
>
> My idea is to write common code for IncomeType and ExpenseType in it's 
> base class transaction_type which extends ActiveRecord::Base. 
>
>
Couple things:

* the code you posted has a single transaction_items table, but two classes 
(Income and Expense) that both descend from ActiveRecord::Base. That 
definitely won't work. If you really want a common transaction_items table, 
you'll need to include a column to put the STI type in and a base class of 
TransactionItem rather than a module.

* as noted previously, if you have a column on transaction_items called 
`transaction_type_id` but want to refer to the corresponding association as 
`expense_type` or `income_type`, you'll need to pass the `foreign_key` 
option to `belongs_to`.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/874743f6-553f-4ef9-b248-20ad78ae72e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to