Grafted fields

A place for users and developers of the Xataface to discuss and receive support.

Grafted fields

Postby wisni1rr » Wed Mar 07, 2012 9:46 am

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!
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Grafted fields

Postby shannah » Wed Mar 07, 2012 10:36 am

I have attached a section of an incomplete manual that explains a little bit more about grafted fields. Perhaps this will help.
Attachments
test.pp119-121.pdf
Section on grafted fields
(97.19 KiB) Downloaded 968 times
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Grafted fields

Postby wisni1rr » Tue Mar 13, 2012 12:01 pm

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
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Grafted fields

Postby shannah » Tue Mar 13, 2012 12:34 pm

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)
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Grafted fields

Postby wisni1rr » Thu Mar 22, 2012 9:18 am

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?
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Grafted fields

Postby shannah » Thu Mar 22, 2012 10:00 am

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Grafted fields

Postby wisni1rr » Thu Mar 22, 2012 10:29 am

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
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Grafted fields

Postby wisni1rr » Wed Mar 28, 2012 9:47 am

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".
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Grafted fields

Postby shannah » Wed Mar 28, 2012 11:08 am

Don't use where clauses in the __sql__ grafted field directive. Use security filters for that.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Grafted fields

Postby wisni1rr » Wed Mar 28, 2012 11:33 am

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!
wisni1rr
 
Posts: 107
Joined: Mon Feb 13, 2012 9:03 pm

Re: Grafted fields

Postby shannah » Wed Mar 28, 2012 11:45 am

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.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Grafted fields

Postby bkeefe » Thu Oct 11, 2012 7:31 pm

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.
bkeefe
 
Posts: 3
Joined: Wed Sep 12, 2012 11:57 pm

Re: Grafted fields

Postby shannah » Fri Oct 12, 2012 8:06 am

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 24 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved