Hi all
i think im too stupid to get how i can use models with assotiations.
I have 3 tables in mysql:
Code:
create table webmasters (
id int(11) auto_increment not null,
firstname varchar(80),
lastname varchar(80)
)
create table billingproviders (
id int(11) auto_increment not null,
name varchar(80)
)
create table webmasters_billingproviders (
webmaster_id int(11),
billingprovider_id int(11)
own_billingprovider_id varchar(80)
)
i have created 2 controllers and 2 models
Code:
script/generate model Webmaster
script/generate controller webmaster
script/generate model Billingprovider
script/generate controller Billingprovider
when i wouldn''t know that there''s a far better way i would use
following
query to get the information i want:
Code:
@info = Billingprovider.find_by_sql "select a.name, b.replacement_id from
billingproviders as a left outer join webmasters_billingproviders as b on
a.id=b.billingprovider_id where b.webmaster_id=''1''"
this code would add following to the @info hash.
Code:
+--------+----------------+
| name | replacement_id |
+--------+----------------+
| CCBill | 123456 |
+--------+----------------+
is there a ruby way how to do this with assotiations like has_many and
belongs_to and get the required information over objects?
sorry about this newbie question but i didn''t find a tutorial that
explains how to use models and assotiations when working with more then 2
tables.
thanks for every information about good tutorials or examples.
Chris