I am writing a specification for someone to create a model generator based on an existing database. To illustrate the specification, I created the following dummy database:
And here is a code snippet showing how to manipulate various tables:
<?php // DISPLAYING VALUES $companies = new $Companies(); $companies->get_all(); foreach ($companies as $company) { echo "Company name: " . $company->name; // 1-n relationship FROM company table so company_type is 1 object echo "Type of company: " . $company->company_type->name; // 1-n relationship TO company table so portfolios is a collection of 0 // or more objects foreach ($company->portfolios as $portfolio) { foreach ($portfolio->customers as $customer) { echo $customer->amount_of_contract; echo $customer->name; } } } // ADDING A PORTFOLIO $companies = new $Companies; $company = $companies->get_by_name('mycompany'); $portfolio = new $Portofolio; $portfolio->company_id = $company->id; $portfolio->year = '2012'; $portfolio->create();
Since Iโm not very technical, I really donโt know if this is possible, and if so, how much work is involved in creating the appropriate models. Accordingly, I would like to ask the following questions:
Q1: From the coding style, do you see everything that would not be (reasonably) feasible?
Q2: will any value add an extra step for the portfolio_has_customer
table or will it access the amount_of_contract
property through the customer
object as described above?
Q3: Is there an alternative for handling the nm
portfolio_has_customer
relationship that would be less difficult to implement than the one described above?
source share