fuel / oil

Fuel PHP Framework - Fuel v1.x Oil command-line package
http://fuelphp.com/docs/packages/oil/intro.html
106 stars 67 forks source link

oil Scaffolding with Foreign Keys #38

Closed sorinpohontu closed 13 years ago

sorinpohontu commented 13 years ago

Let's say we have 2 tables, linked with a Foreign Key.

CREATE TABLE cities ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, created_at int(11) NOT NULL, updated_at int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB;

CREATE TABLE users ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, city_id int(11) NOT NULL, created_at int(11) NOT NULL, updated_at int(11) NOT NULL, PRIMARY KEY (id), CONSTRAINT users_ibfk_0 FOREIGN KEY (city_id) REFERENCES cities (id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB;

Issues:

  1. How can I specify to oil (on generate) that city_id should be a Foreign Key ?
  2. For tables with FK, oil should generate controllers with _has_one / _belongs_to, according to foreign keys.
  3. When views are created for 'users', the view should display, by default, City Name (from cities) instead of city_id.
  4. When _form is created for editing 'users', the form should generate a Form::select for city_id, with values taken from cities (Name).

I have opened a forum post for this: http://fuelphp.com/forums/topics/view/4315

Regards, /Sorin

philsturgeon commented 13 years ago

You open up the migration before it is run and add that if you like. Scaffolding is for creating basic code nice and quickly, not super-mega optmised for MySQL-specific code.

Change the migration, change the model, done.