Little puzzle

Hello,

I have a problem and wonder if anyone has a smart idea:

How can I efficiently verify a given relationship name?

I have a String containing the name of a Servoy relationship and like to find out if that exists. Does anyone have a bright idea on how to do is without accessing every form in a loop?

I tried to do a query in the repository, but it is a little difficult to figure out which solutions/modules are currently loaded and therefore have to be queried. Maybe there is a relation in the repository, but that sits in a solution that is not loaded…

Thanks
Patrick

What about relation_xxxx.hasRecords inside a try/catch?

Paul

But that needs a starting point like a record or a form. You can’t just fire a databaseManager.hasRecords(relation) into the sky, can you? I think it will always return false, if you just do that let’s say in a global method. But keep on puzzling :D

mmm, if you do not know the form/table on the left side of the relation, then testing for it will become a bit difficult, I think

Paul

It’s simple:

if(relationName)
{
   //EXISTS
}

DO use this before trying to reference any fields, counts, etc. It will save you a lot of headaches.

Hello Bob,

that also requires that the relation is reachable from where you are (form/record). It does not work for example if you just have the name of the relationship, no idea what the left and right side tables are and want to test if the relationship exists at all inside the solution.

Thanks
Patrick

pbakker:
mmm, if you do not know the form/table on the left side of the relation, then testing for it will become a bit difficult, I think

Paul

Hello Paul,

I know the table on the left side, but I am not sure that I can get a form (maybe a form for that table doesn’t even exist). Do you have an idea what can be done if you know the table?

Thanks
Patrick

If you know the form, then I know what to do, but i think you know that yourself as well :D

If you know the table, you could loop though the forms, get their table, compare yadayadayada…

But, if, as you say, ther emight not even be a form based on this table, it’s getting to the point where I do not think it’s possible to evaluate the validness of the relationName stirng.

paul

except for a query in the repository :cry:

Try:

 if(relationName != undefined)
{
  //EXISTS
}

but that relation will always be undefined if I don’t know the right starting point (a form or a record)…

I just wanted to add my 2 cents regarding my view of relationships:

Men are from Mars / Women get half

Try:

var relationString = "your relation name here";
var formName = forms.allnames;
for(i=0; i < formName.length; i++){
	if(forms[formName[i]][relationString] != undefined){
		//Exist
	}
}

Thanks! But I knew that:

Does anyone have a bright idea on how to do is without accessing every form in a loop?

patrick:
How can I efficiently verify a given relationship name?

If you don’t know on which table the relation is build is impossible todo without looping trough all the forms (which is not advised todo)

I know the table on the left side and the table on the right (the names of the tables)… But how does that help me?

hmm, you are correct, that even does not help, but why whould you store a relation name as string somewhere and validate the name later on?

For my search. Currently I have to use Servoy relations for searching since I can’t use joins (you remember that discussion on Joins and loadRecords). If I want to use related data, I need relations. The names of those relations are needed to be able to search. Since some of the modules in my solution are built by my customer themselves, they need to enter their table/relation info as well. For stability reasons it would be need to be able to find out if the relation name that they punch in is valid (at least that it exists).

There is a solution for your “Joins and loadRecords”, there is currently no way to verify if a relation name is valid…but how whould you use such a relation name in your search?

Jan Blok:
There is a solution for your “Joins and loadRecords”

You mean the google style? I am thinking about how my interface would look like. I am still brainstorming about this…

but how whould you use such a relation name in your search?

I am doing that now. The user tells me what is the main search table (what he wants to find). I have all tables in one of my tables. I also have a table containing all relevant relations. So I know all tables that can be “seen” from the “main search table” and offer those a search criteria.

In the search method I do something like (out of my head)

forms[searchform].controller.find()
if (aRelation)
{
    forms[serarchform][aRelation][searchField] = ...
}
else
{
    forms[serarchform][searchField] = ...
}

That’s pretty easy and works well (expect for LEFT OUTER… - you know what I mean).