4 Replies Latest reply on Sep 17, 2012 12:30 PM by Jon Tara

    rhom database connectivity

      Can we have 2 databases within a model.If yes,then how.Otherwise,how can we connect two tables from different models to make a schema??

       

       

      Thanks,

      Divyansh

        • Re: rhom database connectivity

          anyone knows about it?

            • Re: rhom database connectivity
              Jon Tara

              I don't understand your question. What do you mean by "two databases within a model"?

               

              You can logically-connect tables from different models by populating an attribute of each model with a common ID, as you would with any relational database.

               

              Rhom is a fairly basic ORM, and has no internal methods for relating models. There are declared relationships, but these are used only to manage synchronization using RhoConnect.

               

              So, you must write code to do relational operations yourself. If you have, say, an Employee model and a Timecard model, you might relate the two using employee-id. If you want to retrieve all of the timecards for an employee, you would first need to know the employee-id for the employee (which you might, for example, look-up by searching by name), and then do a find() on the timecard model searching for that employee-id.

                • Re: rhom database connectivity

                  so thats what I am looking for,how will I refer one model from another,is it the same way we do it for methods or will there be any other lines of code for that...do you have any sample cod on github showing this thing?

                    • Re: rhom database connectivity
                      Jon Tara

                      Every model is accessible from any of your Ruby code. You do not even need a require statement. You simply refer to the model as you would in your controller.

                       

                      e.g.

                       

                      Employee.find(...)

                       

                      Timecard.find(...)

                       

                      I don't know what sample you would need for this. It is set-out clearly in the documentation. Just use find to look-up records based on the corresponding ID.