http://www.livestream.com/hashrocket/video?clipId=pla_686e2833-4950-4389-8c69-46776949da1e
He talked about using Mongo for hierarchical data and SQL for
relational data. I'm trying to wrap my head around what that means in
practice for a Rails app.
I've got an existing construction safety application. I'm spiking a
conversion of some of the domain model to use Mongoid. I was hoping
someone here could share some advice about which models are better
suited for Mongo and which are better suited for SQL.
Company
has many Projects
Project
has many Safety Inspectors (users)
has one Safety Manager (user)
has one Project Manager (user)
has many Zones
has many Incidents
Safety Category
has many Safety Issues
Incident
belongs to Project
belongs to Safety Issue
belongs to Safety Inspector
So I'm thinking that Safety Category/Issue is clearly hierarchical
(even displayed that way to users). More of a grey area for me is
whether it makes sense to convert Company/Project/Incident to Mongo
(that is a hierarchy but once signed in, you're basically only dealing
with Incidents) and whether it makes sense to convert the different
types of users to Mongo (there is a clear hierarchy of bosses and each
successive boss can see/do everything on the app that their direct
reports can).
Any advice would be greatly appreciated.
Thanks,
--
Dan Croak
@Croaky
With mongomapper I would have the User as a separate collection and
have an arrays of the id's for the different members of the project,
although I'm not sure if that's the best way to go about it with
mongoid.
On Jan 16, 7:56 pm, Dan Croak <dcr...@thoughtbot.com> wrote:
> I watched this video of Durran talking about Mongoid:
>
> http://www.livestream.com/hashrocket/video?clipId=pla_686e2833-4950-4...
I was hoping to migrate fully over to mongodb, although it's not a
dealbreaker. On a side note I tried to fork devise to add a Mongid
adapter
http://github.com/bitzesty/devise/tree/mongoid
However I get the following error when using :validatable
TypeError ([] is not a symbol):
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/durran-
validatable-2.0.1/lib/validations/validates_uniqueness_of.rb:8:in
`send'
It seems to be due to the scope being an empty array by default
Matt
> >http://www.livestream.com/hashrocket/video?clipId=pla_686e2833-4950-4...
Images
I think I heard you say in the video you use CarrierWave? Looks cool,
I'm going to prefer to store images on S3 for this project. Each
Incident has many images (probably 2-5, as high-res as mobile phones
will allow). Does it make sense to store these as embedded documents
where their only values are links to S3 URLs?
Users
If passwords are the issue in Mongo, does it make sense to simply
store encrypted passwords in a relational db and move the User model
to Mongo if a domain model suggests it is necessary?
Lookup data
Can you explain a little further why lookup data is better suited for
SQL? You're right that Zone qualifies as such.
Controllers
I'm very familiar with Inherited Resources from our last few projects
and can see how it might fit. Let-It-Be looks interesting. I've always
had a beef with copying over instance variables. Will keep an eye on
it, thanks.
Thanks again, Durran. Really appreciate your time. Will report back if
we push this app into production with any of it using Mongo. I like
the Mongoid/Hashrocket/Pharma app story. Jives well with the
cleanliness and professionalism of the Mongoid source. Maybe
Mongoid/thoughtbot/construction safety story could bolster that?
--
Dan Croak
@Croaky
Thanks, Durran. This is helpful. I don't think we need to schedule a
Skype session but I have a couple of other questions if you'll indulge
me...
Images
I think I heard you say in the video you use CarrierWave? Looks cool,
I'm going to prefer to store images on S3 for this project. Each
Incident has many images (probably 2-5, as high-res as mobile phones
will allow). Does it make sense to store these as embedded documents
where their only values are links to S3 URLs?
Users
If passwords are the issue in Mongo, does it make sense to simply
store encrypted passwords in a relational db and move the User model
to Mongo if a domain model suggests it is necessary?
Lookup data
Can you explain a little further why lookup data is better suited for
SQL? You're right that Zone qualifies as such.
Controllers
I'm very familiar with Inherited Resources from our last few projects
and can see how it might fit. Let-It-Be looks interesting. I've always
had a beef with copying over instance variables. Will keep an eye on
it, thanks.
Thanks again, Durran. Really appreciate your time. Will report back if
we push this app into production with any of it using Mongo. I like
the Mongoid/Hashrocket/Pharma app story. Jives well with the
cleanliness and professionalism of the Mongoid source. Maybe
Mongoid/thoughtbot/construction safety story could bolster that?
> Given Kyle's comment he's actually right... I'll just need to add support
> for Mongoid in a few of the gems out there to make this easier... Devise
> will probably be the first but I think someone was already working on that.
Mongoid can be used with Clearance right now without problem:
class User
include Mongoid::Document
include Clearance::User
field :email
field :encrypted_password
field :salt
field :confirmation_token
field :remember_token
field :email_confirmed, :type => Boolean, :default => false
end
--
Dan Croak
@Croaky
I don't think there's anything else in the module that Mongoid can't handle:
http://github.com/thoughtbot/clearance/blob/master/lib/clearance/user.rb
Dynamic finders (find_by_email) are cool, right?
--
Dan Croak
@Croaky
class User
include Mongoid::Document
include Mongoid::Timestamps
extend Clearance::User::ClassMethods
include Clearance::User::InstanceMethods
include Clearance::User::AttrAccessor
include Clearance::User::Callbacks
.# . . manually added validations and fields
def self.find_by_email(email)
self.first :conditions => { :email => email }
end
end
I'm planning on adding Clearance to another class in my app and was
waiting until then to pull that stuff out into its own module.
- HP
On Jan 20, 7:49 pm, Scott Weeks <scott.we...@gmail.com> wrote:
> Curses, I forgot about that. I hacked it in (just added a class
> method) This is what my User class looks like
>
> class User
> include Mongoid::Document
> include Mongoid::Timestamps
>
> extend Clearance::User::ClassMethods
> include Clearance::User::InstanceMethods
> include Clearance::User::AttrAccessor
> include Clearance::User::Callbacks
>
> .# . . manually added validations and fields
>
> def self.find_by_email(email)
> self.first :conditions => { :email => email }
> end
> end
>
> I'm planning on adding Clearance to another class in my app and was
> waiting until then to pull that stuff out into its own module.
>
> On Jan 20, 2010, at 1:36 PM, Dan Croak wrote:
>
>
>
> > Ah. So that would require a fork of validatable or need to wait until
> > ActiveModel::Validations are used?
>
> > I don't think there's anything else in the module that Mongoid can't
> > handle:
>
> >http://github.com/thoughtbot/clearance/blob/master/lib/clearance/user.rb
>
> > Dynamic finders (find_by_email) are cool, right?
>
> > On Wed, Jan 20, 2010 at 1:33 PM, Scott Weeks <scott.we...@gmail.com>
On Jan 20, 7:22 pm, HP <hanspet...@gmail.com> wrote:
> There is a Mongoid fork of Devise waiting to be merged in:http://github.com/plataformatec/devise/issues#issue/85Needs help
Try adding this to an initializer (config/initializer/warden.rb):
class Warden::SessionSerializer
def serialize(user)
user.id
end
def deserialize(id)
User.criteria.id(id).first
end
end
The default/built-in Warden::SessionSerializer will not work with
Mongoid. I'm using RailsWarden, and the above works.
- HP
Devise serializer:
class Warden::SessionSerializer
def serialize(record)
[record.class, record.id]
end
def deserialize(keys)
klass, id = keys
klass.find(:first, :conditions => { :id => id })
end
end