On 19 April 2013 14:45, Leandro Peracchi <[email protected]> wrote:
> Hi guys!
>
>   I am an old procedural programmer learning Rails and object
> orientation.  :)
>
>   I wish to create a little system to help my wife who is a teacher.
>
>   The attached PDF file has the preliminary Entity-Relationship model.
>
>   I am having a rough time trying to put this model into Rails...  :(
>
>   Looking at the model I can think about the SQL code necessary.  But I
> think Ruby and Rails is here to help and speed the development process.

It is rare to have to use SQL directly in Rails.  If you have to then
you are probably doing something wrong.

> ;)
>
>   For some examples:
>
>     Who teaches at school "x"?

@school.teachers

>
> SELECT people.name FROM people WHERE people.id IN
>   (SELECT team_has_teachers.person_id FROM team_has_teachers WHERE
> team_has_teachers.team_id IN
>     (SELECT teams.id AS team_id FROM teams WHERE teams.school_id =
>       (SELECT schools.id AS school_id FROM schools WHERE schools.name =
> 'x')))
>
>
>     Who learns from teacher "x"?

@teacher.pupils
though in pra
>
> SELECT people.name FROM people WHERE people.id IN
>   (SELECT team_has_students.person_id FROM team_has_students WHERE
> team_has_students.team_id IN
>     (SELECT team_has_teachers.team_id FROM team_has_teachers WHERE
> team_has_teachers.person_id =
>       (SELECT people.id FROM people WHERE people.name = 'x')))
>
>
>     Who is in team "x"?

@team.members

>
> SELECT people.name FROM people WHERE people.id IN
>   (SELECT team_has_students.person_id FROM team_has_students WHERE
> team_has_students.team_id IN
>     (SELECT teams.id FROM teams WHERE teams.name = 'x'))
>
>
>   Any help is welcome!

The details are not correct as I have not looked at the ER diagram,
and it is arguable whether you should start with such a diagram in the
first place, but in order to understand the basics of what rails can
do for you I suggest you work right through a good tutorial such as
railstutorial.org, which is free to use online.  Also look at the
Rails Guides, particularly ActiveRecord Associations.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to