Forum: Ruby why doesn't this "belongs_to" line of code, using options override, not work??? (need help using bel

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Greg H. (Guest)
on 2008-10-30 23:23
(Received via mailing list)
Hi,

Anyone able to help out in how you use "belongs_to" options so that I
can have a 2nd attribute that also belongs to an associated table.  My
recurring items class belongs to a "transaction", however I also want
a secondary recurring item field "journal_source_id" to be able to
reference a "bank_account" item.

The following doesn't quite seem to work?
  -----------------
  belongs_to :journal_source,  # I made this name up, i.e. it isn't
actually in a table.  It's the "journal_source_id" field that is in
the recurring table
    :class_name => "BankAccount",
    :foreign_key => "journal_source_id"
  ---------------



Background below:

---- recurring class ----
belongs_to :bank_account    # recurrance associated with bank account
belongs_to :journal_source,  # HELP ME HERE: Want to have another
reference to a "bank acount" here
    :class_name => "BankAccount",
    :foreign_key => "journal_source_id"

-- recurrings table ----
#  id                  :integer(4)      not null, primary key
#  bank_account_id     :integer(4)      not null
#  journal_source_id   :integer(4)      <==== THIS IS THE ONE

---- bankaccounts table ----
id
.
.
Brian C. (Guest)
on 2008-10-31 00:45
Suggest you try http://rubyonrails.com/community

ActiveRecord is a sufficiently large project in its own right that it
has its own mailing lists, and you're more likely to find experts there.
This topic is locked and can not be replied to.