phreeze icon indicating copy to clipboard operation
phreeze copied to clipboard

Missing master-detail?

Open gerardus opened this issue 11 years ago • 18 comments

Hi, first of all, congratulations for your work, it looks very promising. I've been playing with the builder and some simple DB's, and it doesn't seem to generate master-detail views. I I create a table ORDER( pk ID) and a detail table ORDERITEM (pk ID, fk ORDER_ID), i get a list of orders and a list o order items, but it would be nice to have a master-detail editor with the order fields and the order items. Is there something I am missing?

Best regards,

Gerard.

gerardus avatar Jun 04 '13 17:06 gerardus

The only thing that Phreeze does in that respect is that on your order item page - when you look at that you should see a drop-down where you can select which order the item belongs to. The automatically generated app doesn't do the reverse - which of course is showing child records of a record. It's not super difficult to write that in but it just isn't in the generated code because it's difficult to know when it's relevant or necessary to print child records.

One thing you do gain from Phreeze in this case is not so much an automatically generated and working app. You would need to write most of your app. But you will be able to use the ORM to query data easily and the Controller setup to organize your code and provide mechanisms authentication.

For example you would gain functions something like this, depending on your table names:

$order = $this->Phreezer->Get('Order',22);

foreach ($order->OrderItems as $item)
{
    echo $item->Price;
   // etc...
}

Another nice thing is that the auto-generated code may work for certain parts of the app without a whole lot of tweaking. For example, it may work really nicely for managing products or inventory.

jasonhinkle avatar Jun 05 '13 00:06 jasonhinkle

Thanks a lot for the explanation, Jason.

Gerard.

On Wed, Jun 5, 2013 at 2:55 AM, jasonhinkle [email protected]:

The only thing that Phreeze does in that respect is that on your order item page - when you look at that you should see a drop-down where you can select which order the item belongs to.

In that particular case it's actually not that useful because it doesn't really reflect the way orders and order items are usually. Phreeze doesn't understand anything about your business logic or the meaning of any of your data. It only understands the foreign key between the two tables. A normal app would have many tables and lots of relationships and Phreeze has no way to understand what tables are major elements vs lookup tables, vs a User or anything else.

What you would gain from Phreeze in this case is not so much an automatically generated and working app. But you will be able to use the ORM to query data easily and the Controller setup to organize your code and provide mechanisms authentication.

For example you would gain functions something like this, depending on your table names:

$order = $this->Phreezer->Get('Order',22);

foreach ($order->OrderItems as $item) { echo $item->Price; // etc... }

— Reply to this email directly or view it on GitHubhttps://github.com/jasonhinkle/phreeze/issues/109#issuecomment-18949302 .

gerardus avatar Jun 05 '13 08:06 gerardus

What I was thinking jason is just as you can select on the builder for which tables which package to generate, create a new package which generates de detail view for lets say.... table Invoice has an action to drill down to InvoiceDetail, is it worth it? what do you think?

titu00 avatar Jul 25 '13 15:07 titu00

I think that would be great. Really the whole idea of the builder is to be able to add templates for all kinds of things so you can generate the boring, repetitive parts.

Master/Detail relationships are not hard to build at all, but it is kinda hard to figure out when to build them, or for which tables they're relevant from a business-logic perspective. Being able to manually select one particular table would allow you to build one or two for only the tables you want.

jasonhinkle avatar Jul 25 '13 17:07 jasonhinkle

Yes but just to analyze the roadmap you intend for phreeze would you prefer to add a "Custom value text box" on the table list of the builder, whicha can be use for a particular package or would you prefer to add strict database schema such as table Invoice would be master of table DetailInvoice ?

titu00 avatar Jul 25 '13 17:07 titu00

I think I understand what you're saying. Well in general I try to avoid any specific table schema or naming convention so that Phreeze can work with any schema. So I would probably be in favor of something in the application options area of the builder if that's possible.

At one point in time I had Phreeze look at the DB column "comments" metadata to use that for specific things, but it didn't work very well due to size limitations of the comments. Also it started to feel a little weird to put that in the database!

jasonhinkle avatar Jul 25 '13 17:07 jasonhinkle

Jason, I read on another post that you were planning some changes on the generator so I decided to show you my approach on the master detail.

I've created the most basic type of master-detail template, but had to add a new textarea for each table on the generator which is a JSON config.

e.g. for the DetailPayment table:

{ "replaceVars":{ "controllerName":"ViewDetailPayments" }, "masterTable":"Payments", "childField":"IdPayment" }

replaceVars is used to replace on the phreeze.masterdetail.config file for the templateFileName and this is already implemented on the GeneratorController so it can be use for any other package.

so my package config file looks:

[files] phreeze.titu/templates/ListView.tpl.tpl templates/{$controllerName}ListView.tpl.php 0 phreeze.titu/libs/Controller/Controller.php.tpl libs/Controller/{$controllerName}Controller.php 0

The result is that I used your backbone template for the child listing but the master info I pass it to the ListView.tpl.php.

I can upload some screenshot, but I would like to now first what do you think about this?

Thanks, Esteban

titu00 avatar Aug 03 '13 04:08 titu00

cool! some screenshots or even if you want to send a pull request would be great. i don't think i fully understand the changed that you made yet, but it would be great to see it.

jasonhinkle avatar Aug 03 '13 08:08 jasonhinkle

These are the screenshots. I don't have git nor my Github account set on this computer. In order for this package to work you should first generate the savant default package for the tables you will generate the master child. Then you load again the generator and change the options.

phreeze - builder - step 1 b

phreeze - builder - step 1

Once you generate just drop the zip on the site directory. You should also add the route on _app_config.php in this case:

'GET:customerpackage' => array('route' => 'CustomerPackage.ListView'),

phreeze - builder - step 2

As the child tables is generator with all of Jason's magic,. you still have the same way to alter or delete rows.

update child

titu00 avatar Aug 03 '13 22:08 titu00

That looks cool titu00! :) Hopefully you can send Jason a pull request and we can get this into Phreeze. Perhaps additional config like this (and other yet to be determined functionality) could be available via an 'Advanced' option when generating the app?!

JedMeister avatar Aug 04 '13 02:08 JedMeister

Aha, I see. I'm really psyched to see some work happening on the templates! One suggestion - Phreeze already does understand everything about the relationship between the two tables so you don't actually have to specify the relationship fields in the config file. For any given table, Phreeze knows all of the "Sets" (foreign tables) that are attached to it. You could make the config even more simple by simply just telling that table which of it's "Sets" you want to see on the detail page:

{
  displayChildObjects: [Package]
}

or, the reverse (more similar to your config file)

{
  displayParentObjects: [Customer]
}

In a really old version of Phreeze, I did actually generate something very similar to what you've done. I think it can be really useful.

jasonhinkle avatar Aug 04 '13 04:08 jasonhinkle

This is definately not ready to commit. In order to keep quality on Phreeze I should modify this as jason suggested and add backbone model for master data. But if anyone is willing to see the code just message me. I don't know when I will have time to complete this feature, just shared to see if anyone had new ideas as Jason pointed out.

titu00 avatar Aug 06 '13 18:08 titu00

if anybody needs this:

https://github.com/titu00/phreeze/tree/master_detail

I think this project needs more contribution than questions. 99.9999% was done by jason. Start commiting templates or any change you think will be useful.

titu00 avatar Aug 06 '13 20:08 titu00

haha, thanks for that! I'm having a crazy week so I'm not getting around to stuff quickly but I'll have time to check this out more thoroughly hopefully pretty soon.

jasonhinkle avatar Aug 07 '13 17:08 jasonhinkle

Probably this is not the correct thread. But I've committed on the same branch.

actioncustomers

The TR click has been disabled and the JSON config for this package example is: { "actions": [ { "label": "Edit", "icon": "icon-pencil", "href": "javascript: page.actionEdit(&id&);" }, { "label": "View Detail", "icon": " icon-search", "href": "customerpackage?id=&id&" } ] }

screenshot:

customerconfig

I've used &id& tag to replace with the underscore template code for the id of the model. I know this probably isn't the way Jason would prefer but if anyone needs this or is willing to start working from here your welcome.

titu00 avatar Aug 09 '13 21:08 titu00

Forgot to tell you the package name is "Action column crud with savan" so you'll have to select this one.

titu00 avatar Aug 09 '13 21:08 titu00

Sorry for the rebirth of this old thread/issue, but is anything working on actual phreeze like this master-detail? How can I do? Any contribution is necessary? Thanks a lot.

jrborbars avatar May 13 '16 00:05 jrborbars

Hello, I need too a example of master detail CRUD working for my web system. Any idea?

guilhermegielow avatar Sep 12 '16 19:09 guilhermegielow