Posts that Ben is monitoring
|
Sep 4, 2007
|
Topic: VibrantInk VS settings Thanks guys, I had thought that John Lam’s theme was the one I saw, but I was not sure. I’m gonna try all of them out. |
|
Aug 31, 2007
|
Topic: associations and join tables This is a perfect solution… I’ll just add that there’s one other way to do it (also mentioned in Jamis’ article), and that is to use association extensions.
class Country < ActiveRecord::Base
has_many :carrier_countries
has_many :carriers, :through => :carrier_countries do
def major
find(:all, :conditions => "major = 1")
end
end
end
I sometimes prefer this syntax if you’re going to have more than one type of filter. For example, if you wanted to eventually add carriers that were small, mid-sized, etc… doing it this way, you would then have methods like country.small_carriers, country.major_carriers, etc. With the block syntax it is bit cleaner, as this creates methods like country.carriers.major and country.carriers.small. |
|
Aug 31, 2007
|
Topic: VibrantInk VS settings Yeah, John Lam’s theme for VS (the second link) is pretty much what we had there, but a bit more thorough. I’d recommend it. |
|
Aug 31, 2007
|
Topic: associations and join tables Thanks Ben! That worked perfectly after one change. All I had to do was define a :source option.
class Country < ActiveRecord::Base
has_many :carrier_countries
has_many :carriers, :through => :carrier_countries
has_many :major_carriers, :through => :carrier_countries, :source => :carrier, :conditions => 'major = 1'
end
Here’s more info on the :source option:
:source: Specifies the source association name used by has_many :through queries. Only use it if the name cannot be inferred from the association. |
|
Aug 31, 2007
|
Topic: VibrantInk VS settings Not sure if I still have my copy… Brian, any chance you’ve still got it? |
|
Aug 30, 2007
|
Topic: associations and join tables I’m having a hard time wrapping my head around an association problem. I have 2 classes with a many to many relationship: Carrier and Country. I created a join table model (CarrierCountry) and defined a through association that gives me @carrier.countries and @country.carriers and this works great. My problem is I’ve added a field to the CarrierCountry model that defines if the Carrier is a major carrier for that Country. I’m trying to define an association that will let me do something like this: @country.major_carriers which should return all the Country’s major Carriers. I can’t figure out where to define the association or if I took a wrong turn somewhere. Code:
class Country < ActiveRecord::Base
has_many :carrier_countries
has_many :carriers, :through => :carrier_countries
end
class Carrier < ActiveRecord::Base
has_many :carrier_countries
has_many :countries, :through => :carrier_countries
end
class CarrierCountry < ActiveRecord::Base
belongs_to :carrier
belongs_to :country
end
|
|
Aug 30, 2007
|
Topic: VibrantInk VS settings Hey guys, I’ve been going through the archived posts in order to catch up with your conversion from .NET to Rails. I, myself, have started the process recently and, like you, I find it very difficult to go back to .NET (especially 1.1, ugh) after a night with Rails. Anyway, one of the back posts had a link to the VibrantInk settings for VS. Do you guys still have that? Glad to be a member of this community. |