Merch Challenges: pulling hair

This post is part of a loose series documenting the development process of Merch. If you want to read more about the app or track along with our progress, head over here. By the way, my partner in crime is @tahaadiljalil, a rockstar and international badass I met at Bitmaker Labs and all the work for Merch is being done at Filament Creative in Toronto.

I’m hoping if you’ve found your way here it’s because you, like me, are working on building a Rails web app with a Parse backend and it’s making you want to call your Dad, go back to school, do an ‘Eat, Pray, Love’ thing, whatever. Maybe that’s a little overboard (in truth we’re having a great time building it), but the original statement stands; if Parse + Rails is freaking you out a little, I hope you feel not quite so alone out there.

Taha and I found out this week that the associations we’d made between two of our Merch models weren’t just unnecessary, they were breaking our relationships on Parse. We ended up solving the problem with the “Pointer” columns in Parse’s data browser but it took a while to get there. Parse, being a non-relational (NoSQL) database, behaves differently than a vanilla Rails environment would. Neither Taha or I had experience working in a NoSQL database and the learning curve felt a little steep.

Our goal was to build a many-to-many relationship using either has_and_belongs_to_many or has_many, through:. So, in a normal Rails app you might have something like this:

class User < ActiveRecord::Base

  has_many :bands, through: :members
.
.
.
end

In a Parse-backed app running the ‘parse_resource’ gem, it ends up looking like:

class User < ParseUser

  fields :username, :email, :password, :first_name, :last_name, :role, :organization_name
.
.
.
end

Do you see what happened there? We lost our associations and gained a line of code which defines the fields of the User model. The difference between those two blocks of code represent approximately one afternoon of lost time and one major lesson learned: the associations you use in a typical Rails environment will break your data on Parse (and other NoSQL DBs.. probably). Taha and I nearly pulled all of our hair trying to figure out why we couldn’t set up a basic many-to-many relationship in Merch and it came down to finding out that (associations in parse_resource are deprecated)[https://github.com/adelevie/parse_resource].

As soon as we removed them and relied solely on the Pointers from Parse, things started to come together, our join tables were working how we expected them to and we could move on to the next piece of the Merch puzzle.

 
3
Kudos
 
3
Kudos

Now read this

Merch Challenges

This is the spot I’m using to document some of the challenges the Merch team and I have faced over the course of the project. I’ll try and include code snippets as much as possible to show what we’re dealing with but that all depends on... Continue →