Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the point of Models for subscribers? #67

Open
AdamKyle opened this issue Jan 23, 2015 · 1 comment
Open

What is the point of Models for subscribers? #67

AdamKyle opened this issue Jan 23, 2015 · 1 comment

Comments

@AdamKyle
Copy link

I am actually confused by this because, take the following example:

class User < ActiveRecord::Base
  extend FriendlyId
  include Promiscuous::Subscriber
  include UserConcerns

  before_save :add_to_blog_owner_group

  subscribe :first_name, :email, :user_name, :last_name, :auth_token

  friendly_id :user_name, use: [:slugged, :finders, :history]

  has_and_belongs_to_many :blogs, join_table: 'blogs_users', :dependent => :destroy
  has_and_belongs_to_many :roles, join_table: 'roles_users', :dependent => :destroy

  has_many :posts, through: :blogs, :dependent => :destroy
  has_many :pages, through: :blogs, :dependent => :destroy
  has_many :blog_roles, :dependent => :destroy

  has_many :group_memberships, :dependent => :delete_all
  has_many :groups, :through => :group_memberships, :dependent => :delete_all
  has_many :roles, :through => :group_memberships, :dependent => :delete_all

  def add_to_blog_owner_group
    self.add_group_membership(Group.find_by_name('Blog Owner').id, Role.find_by_name('Blog Owner').id)
  end

end

The following model does a lot of things, it sets up relationships, sets up friendly id for clean urls (which I use in API's). But what it does not do is the before_save. Now it does this if I use the terminal or allow you to create a user through this model.

But this model is essentially a read only, you cannot write to it (Only Promiscuous uses it). Promiscuous, its seems, just goes ahead and inserts the data it should listen for based on the attributes.

It actually never does the whole Model.new, Model.save. Which is cool. But then rules like before_save fall apart.

Is there any way to say, before you insert this data, or even "after you insert" do x, once. In this case it should run the add_to_blog_owner_group method.

Maybe I am missing something?

@kareemk
Copy link
Member

kareemk commented Feb 20, 2015

Sorry for the late response. All callbacks are invoked so before_save should have been invoked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants