class TransactionItem < ActiveRecord::Base
belongs_to :transaction
end
class Transaction < ActiveRecord::Base
has_many :transaction_items
def items
self.transaction_items
end
end
class CategoryItems < ActiveRecord::Base
belongs_to :category
end
class Category< ActiveRecord::Base
has_many :category_items
def items
self.category_items
end
end
In an effort to simplify the interface to Objects that have Items
are there drawbacks I’m not seeing to this? or a better way to achieve this goal?
category = Category.first
category.items
# instead of
# category.category_items
transaction = Transaction.first
transaction.items
# instead of
# transaction.transaction_items
Another is by specifying the class (see the
has_manyoptions docs):I don’t see any major issue with your way, though.
The only caveat would be anything that deals with the associations reflectively (e.g., a documentation tool) would use the “real” name, not the additional method. Not a big deal, but something to be aware of.