Hello,
i wonder if the following is possible in Rails (seems like not), and if
not, whether such database structure is discouraged for some good
reason.
I *roughly* want to have
class Payment < ActiveRecord::Base
has_one :purchase
end
where purchase can be either TicketPurchase, or MembershipPurchase, so
to have also
class TicketPurchase < ActiveRecord::Base
belongs_to :payment
end
class MembershipPurchase < ActiveRecord::Base
belongs_to :payment
end
so things need to be polymorphic.
I want this correspond to the following database structure:
payments: id | amount | purchase_type
ticket_purchases: id | number | payment_id
membership_purchases: id | membership_type | payment_id
This does not seem to be possible in Rails, to use polymorphic
associations i would need to store the foreign key in payments table.
Am i right that it is not possible, and is there a good reason for
discouraging such associations?
Thank you,
Alexey.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.