Can you mixin 'has_many', etc., into models?

I've not done any plugin development, but wouldn't that require that the application using the plugin *have* a User class? It seems more like you'd want to introspectively add the has_many to the "parent" thing of BlogUser.

Hmm. Maybe I should go watch that plugin development screencast... :slight_smile:

Peace,
Phillip

Couldn’t you just extend the User class in your plugin?

Define this in your plugin directory:

class User < ActiveRecord::Base
has_many :blogs
end

I’ve not done any plugin development, but wouldn’t that require that
the application using the plugin have a User class? It seems more
like you’d want to introspectively add the has_many to the “parent”
thing of BlogUser.

Hmm. Maybe I should go watch that plugin development screencast… :slight_smile:

Peace,
Phillip

Surprisingly not. If there is not a User class it’ll create a User class for you. If there is a User class, it’ll just extend it. That’s the brilliance of Ruby.

Hi Ryan,

I seem to have overlooked

Define this in your plugin directory:

I see what you’re getting at now. By putting this in the plugin, it will either extend the User class or create it (to basically repeat what you just wrote). Nice point. +1

Peace,

Phillip