Page 1 of 1

Grafted fields

PostPosted: Wed Mar 07, 2012 9:46 am
by wisni1rr
I hate to sound a pain; Can someone help explain grafted fields in a different manner than what is in the wiki:
http://xataface.com/wiki/Grafted_fields

I'm just not grasping the concept of what it achieves. If I understand correctly, it can be used to append an input screen so you can add related records also.

Sorry for the confusion and thank you for you help!

Re: Grafted fields

PostPosted: Wed Mar 07, 2012 10:36 am
by shannah
I have attached a section of an incomplete manual that explains a little bit more about grafted fields. Perhaps this will help.

Re: Grafted fields

PostPosted: Tue Mar 13, 2012 12:01 pm
by wisni1rr
Still slightly lost...

Can someone interpret the following statement in regards to grafted fields:

Code: Select all
__sql__ = "select p.*, d.total from programmation p left join dev d on p.id_programmation=d.id_programmation"


I'm confused on these parts:
p.*
d.total
p
dev d on p.id_programmation=d.id_programmation

Re: Grafted fields

PostPosted: Tue Mar 13, 2012 12:34 pm
by shannah
p.* = All columns in the programmation
d.total = The total column of the dev table
p = The alias for the programmation table
dev d = Assigning the alias "d" to refer to the table "dev"
on p.id_programmation=d.id_programmation = The join clause (joining the programmation table with the dev table on the programmation_id field)

Re: Grafted fields

PostPosted: Thu Mar 22, 2012 9:18 am
by wisni1rr
Here is my attempt at a grafted field. This fields.ini is for the GENERAL table:
Code: Select all
__sql__="SELECT GENERAL.*, MLS.Provider FROM GENERAL LEFT JOIN MLS ON GENERAL.BWA_ID=MLS.BWA_ID"
//

Code: Select all
//
[Provider]
order=13

However the grafted field does not show up on my New/Edit record view.

Am I doing this correctly?

Re: Grafted fields

PostPosted: Thu Mar 22, 2012 10:00 am
by shannah
Grafted fields are read-only. They won't show up on new/edit forms. They will show up in the list view, details view, and the find form.

-Steve

Re: Grafted fields

PostPosted: Thu Mar 22, 2012 10:29 am
by wisni1rr
Thank you for letting me know. I have an appropriate question in another thread that would have been posted next so I will just put in a link to the other thread.

Thanks again,Steve!

http://xataface.com/forum/viewtopic.php?f=4&t=6674

Re: Grafted fields

PostPosted: Wed Mar 28, 2012 9:47 am
by wisni1rr
Code: Select all
__sql__="SELECT GENERAL.*, MLS.Provider FROM GENERAL LEFT JOIN MLS ON GENERAL.BWA_ID=MLS.BWA_ID"


Can you add a where clause to this so it will only display based on the value of the field MLS.Provider?

...WHERE MLS.PROVIDER == "BWA".

Re: Grafted fields

PostPosted: Wed Mar 28, 2012 11:08 am
by shannah
Don't use where clauses in the __sql__ grafted field directive. Use security filters for that.

Re: Grafted fields

PostPosted: Wed Mar 28, 2012 11:33 am
by wisni1rr
I'm lost again!

Can you provide me a manual page on this or an example. The link on the wiki to the man page is broken. I'm trying to bring a related field into my list view. But it needs to check that field in the related record and only display if it is a matches the case, otherwise display NULL.

Thank you and Thank you again!

Re: Grafted fields

PostPosted: Wed Mar 28, 2012 11:45 am
by shannah
A little bit on setting security filters.
http://xataface.com/dox/core/trunk/clas ... b4a1280c63

There are actually quite a few forum posts on the topic but you may have to dig a bit. There may be some stuff in the wiki too.

Re: Grafted fields

PostPosted: Thu Oct 11, 2012 7:31 pm
by bkeefe
May I ask why a WHERE clause in a grafted field statement is inadvisable?

Also, how can I make something like a grafted field that is writeable? It's a lot easier to add information in two tables at once, particularly if they are linked by a one to one relationship.

Re: Grafted fields

PostPosted: Fri Oct 12, 2012 8:06 am
by shannah
May I ask why a WHERE clause in a grafted field statement is inadvisable?


Because when you implement a custom __sql__ query it effectively replaces any occurrences of the table name, in existing SQL queries, with a subquery defined by the __sql__. In some cases, however, it may still use just the table name. It helps if both of these cases are the same except for the addition of the extra columns. If you use a where clause then it may lead to some unexpected results.

Of course, you *can* use a where clause as long as the result of your query has a one-to-one mapping with the rows of the original table.

Most of the time, if you want to use a where clause, you are really wanting a default filter. In these cases you should either set a security filter (if it is a permissions issue), or just add a default search in the beforeHandleRequest method.

-Steve