Rails Table Relations questions

Hello,

I'm breaking my head atm about table relations / associations in Rails.

The idea is this: Collections has many mods, mods have many folders, folders have many items. A collection can have many different versions, the mods associated with a collection, should 'have the same version'. Changelogs are linked to Version, but should differ per Mod.

If I work with ActiveScaffold, things become quite a mess, and I can for instance create a Changelog entry, for a mod that is not part of the chosen Collection, and so on.

This is basically what I have atm: class Collection < ActiveRecord::Base    has_many :mods    has_many :versions end

class Version < ActiveRecord::Base   belongs_to :collection   has_many :changelogs end

class Mod < ActiveRecord::Base    belongs_to :collection    has_many :folders    has_many :changelogs end

class Changelog < ActiveRecord::Base   belongs_to :version   belongs_to :mod end

class Folder < ActiveRecord::Base   belongs to :mod   has_many :folders end

class Item < ActiveRecord::Base   belongs to :folder end

Anybody any ideas? Cheers

If I’ve understood your problem correctly, I would map the core relationships as you have described them and then use validation to ensure the business rules such as a mod of a collection must be of the same version as the collection.

You can use the validation method or perhaps before_save callbacks depending on which suits what you’re doing better.