Many-to-many relationship with multiple models?


I have a simple CMS I’m creating, and the primary model is the
“listing”. A listing habtm (has_and_belongs_to_many) categories (up to
two) - allowing the listing to print its categories and a category to
print its listings. I also need subcategories, which are different from
categories in two ways: a listing can have as many subcategories (from
it’s two categories) as it wishes, and subcategories are displayed
differently in both administration and display views.

So what I have is:

Class Listing < ActiveRecord::Base

has_and_belongs_to_many :categories
has_and_belongs_to_many :subcategories


Class Subcategory < ActiveRecord::Base

has_and_belongs_to_many :listings
belongs_to :categories


Class Category < ActiveRecord::Base

has_and_belongs_to_many :listings
has_many :subcategories


Is this allowed? I ask because I can’t create a listing with
subcategories (from the admin UI) - the UI works fine, there are no
errors, but the new listing has no subcategories and the MySQL DB isn’t