Ask A Question

Notifications

You’re not receiving notifications from this thread.

Pull data from another table in a lookup

Alan Reid asked in Rails

Agreed Jacob!

And yeah you're right about the HABTM table name. The thing about HABTM is that you don't get to ever interact with that table in the middle...so imagine you needed some meta data, like a quantity of the product in each venue...well you're SOL with HABTM. If you have an explicit model as a join table, and do has_many through, then you can add extra columns in like a quantity and do a whole lot more with it. In most cases I find it's better to be explicit about that join table than using HABTM for that reason. Guess I should do an episode on this!

Reply

I will go stand in the corner for an hour and hang my head in shame due to my poor naming conventions,

Seriously though cheers guys, and yeah please do some more episodes on Data and this stuff haha

Reply

Lol naming can be a major PITA... just last night I spent a few hours just renaming things to be a little more future proof.

If you're able to, take some time to build prototypes and do proof of concepts. This will help clear up some of the naming issues that happen when first starting a project. Often you don't know what really makes sense until much further along in the project but by that time it's too late or a major undertaking to rename.

An episode that digs into the associations would be great! Just last week I finally figured out some of the magic in associations, the moment I realized you can designate your own primary / foreign keys and even name it however you'd like was one of the happiest moments in my life!

class Agent < ActiveRecord::Base
  has_many :ar_listed, class_name: 'Abor::AborRetsResi', primary_key: 'agent_id', foreign_key: 'list_agent_mlsid'
end

#this lets me do:
@agent_listed_properties = current_agent.ar_listed

#which returns all the listed properties that agent has! Before, I would have had to do something like:
@agent_listed_properties = Abor::AborRetsResi.where(list_agent_mlsid: current_agent.agent_id)

Of course this may not be the best way to approach this, but seeing how this all works was really eye opening!

Reply

Hmm, markdown isn't parsing for me even though it's showing up in the preview just fine... oh well, this is what I was trying to post as my example:

https://gist.github.com/nanosplit/b50241d66947fbcae3a1020d1f94ab8a

Sorry to spam! :)

Reply

Yeah naming always is a pain, to me it made sense but I understand your points. ;) will fix in v2 of the app haha what I'm building ATM is still very my a proof of concept to show the idea will work and get people on board

Reply

@Jacob, the markdown preview is different than the server side renderer so things are slightly different sometimes.

Reply

@Alan, I added a reactions feature so you can give kudos to other people just like on Github issues. :D

Reply

@chris you made more than just that change i see. looks good mate

Reply

Yeah, there's a lot of changes, I'll be announcing it all shortly!

Reply

might need to look at the subscriber times in the diamond, mine says 3 months but i done 4 payments?

Reply

Woah, very clean!

Think you'll be sharing some of the techniques you used? I'm digging this WYSIWYG editor!

Thanks Chris! :)

Reply

@Alan, they're actually badges, so you get a badge at 1, 3, 6, 12, and 24 months but only after you cross that threshold. Going to be doing similar things for answering questions and whatnot. :D

@Jacob, yeah for sure! The editor is https://github.com/NextStepWebs/simplemde-markdown-editor which I like quite a bit. It was easy to setup, but unfortunately doesn't provide any way of doing @mentions unfortunately. Guess I may have to build my own editor at some point instead.

Reply

@chrris sorry to hijack but the site looks great. love the editor, reactions, series, and more.

Reply

Sweet, I'll have to play around with it, I love a good editor! :)

Did you ever mess with Summernote? http://summernote.org/examples/#hint-for-mention
They support mentions out the box it looks like. I use it on a site and have had no real issues so far.

Anywho - thanks again, and great job!!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,140+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.