self

Tree view using SQL Query

风格不统一 提交于 2019-12-04 13:30:37
I have a regions table of which I want a tree view (table simple ordered as tree) is it possible using sql queries help is appreciated, I tried to do it using self joins but i did not get the desired result. tree view is something like this Indiv Div1 Zon1 div2 zon2 div3 zon3 EDIT: as per Charles Bretana suggetion I tried CTE in below query and it did not give me desired result. WITH Emp_CTE (id, ParentID, name) AS ( SELECT id, ParentID, name FROM eQPortal_Region WHERE ParentID=0 UNION ALL SELECT e.id, e.ParentID, e.name FROM eQPortal_Region e INNER JOIN Emp_CTE ecte ON ecte.id = e.ParentID )

What is the value of self in a Rails model and why aren't obvious instance methods available?

北城余情 提交于 2019-12-04 08:39:39
I have a custom accessor method in my rails 3.1.6 app that assigns a value to an attribute, even if the value is not present.The my_attr attribute is a serialized Hash which should be merged with the given value unless a blank value is specified, in which case it will set the current value to a blank value. (There are added checks to make sure the values are what they should be, but are removed for brevity, as they are not part of my question.) My setter is defined as: def my_attr=(new_val) cur_val = read_attribute(:my_attr) #store current value #make sure we are working with a hash, and reset

How to change self in a block like instance_eval method do?

天涯浪子 提交于 2019-12-04 05:03:39
instance_eval method change self in its block, eg: class D; end d = D.new d.instance_eval do puts self # print something like #<D:0x8a6d9f4>, not 'main'! end If we define a method ourself(or any other methods(other than instance_eval) which takes a block), when print self, we will get 'main', which is different from instance_eval method.eg: [1].each do |e| puts self # print 'main' end How can i define a method(which takes a block) like instance_eval? Thanks in advance. You can write a method that accepts a proc argument, and then pass that as a proc argument to instance_eval. class Foo def bar

What does self do? [duplicate]

梦想的初衷 提交于 2019-12-04 04:35:03
This question already has answers here : Closed 8 years ago . Possible Duplicate: Python 'self' keyword Forgive me if this is an incredibly noobish question, but I never did understand self in Python. What does it do? And when I see things like def example(self, args): return self.something what do they do? I think I've seen args somewhere in a function too. Please explain in a simple way :P It sounds like you've stumbled onto the object oriented features of Python. self is a reference to an object. It's very close to the concept of this in many C-style languages. Check out this code: class

Python, __init__ and self confusion

霸气de小男生 提交于 2019-12-04 04:05:52
问题 Alright, so I was taking a look at some source when I came across this: >>> def __parse(self, filename): ... "parse ID3v1.0 tags from MP3 file" ... self.clear() ... try: ... fsock = open(filename, "rb", 0) ... try: ... fsock.seek(-128, 2) ... tagdata = fsock.read(128) ... finally: ... fsock.close() ... if tagdata[:3] == 'TAG': ... for tag, (start, end, parseFunc) in self.tagDataMap.items(): ... self[tag] = parseFunc(tagdata[start:end]) ... except IOError: ... pass ... So, I decided to test it

Why does Array#each return an array with the same elements?

旧街凉风 提交于 2019-12-04 00:16:44
I'm learning the details of how each works in ruby, and I tried out the following line of code: p [1,2,3,4,5].each { |element| el } And the result is an array of [1,2,3,4,5] But I don't think I fully understand why. Why is the return value of each the same array? Doesn't each just provide a method for iterating? Or is it just common practice for the each method to return the original value? Array#each returns the [array] object it was invoked upon: the result of the block is discarded . Thus if there are no icky side-effects to the original array then nothing will have changed. Perhaps you

iOS First Application “self.userName = textField.text”. When to use self

南笙酒味 提交于 2019-12-03 22:28:38
Here is a code snippet from Apple's "Your First iOS Application" document. - (IBAction)changeGreeting:(id)sender { self.userName = textField.text; NSString *nameString = self.userName; if ([nameString length] == 0) { nameString = @"World"; } NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString]; label.text = greeting; [greeting release]; } I understand that self.username calls the synthesized set method (important since it has a copy flag). Why is textField.text and label.text not self.textField.text and self.label.text. Are the two equivalent? Is the self

Objective C: Difference between self and super

荒凉一梦 提交于 2019-12-03 21:51:03
I am new to Objective C.I am trying aout some example programs.I could not understand how the self and super methods work in objective C. In the pgm below CashTransaction.m [super trackSpending:amount] is called and in CreditCardTransaction.m [self trackSpending:amount] is called.I could not find difference between the self and super.super is for invoking the base class overriden method.and self is for invoking the child class overridden method.This is what my understanding is.please correct me if i'm wrong.Thanks in advace. main.m #import <Foundation/Foundation.h> #import "BudgetObject.h"

Python self and super in multiple inheritance

那年仲夏 提交于 2019-12-03 16:05:11
问题 In Raymond Hettinger's talk "Super considered super speak" at PyCon 2015 he explains the advantages of using super in Python in multiple inheritance context. This is one of the examples that Raymond used during his talk: class DoughFactory(object): def get_dough(self): return 'insecticide treated wheat dough' class Pizza(DoughFactory): def order_pizza(self, *toppings): print('Getting dough') dough = super().get_dough() print('Making pie with %s' % dough) for topping in toppings: print('Adding

how to use a Python function with keyword “self” in arguments

試著忘記壹切 提交于 2019-12-03 15:39:12
i have a function that retrieve a list of stores in Python this functions is called : class LeclercScraper(BaseScraper): """ This class allows scraping of Leclerc Drive website. It is the entry point for dataretrieval. """ def __init__(self): LeclercDatabaseHelper = LeclercParser super(LeclercScraper, self).__init__('http://www.leclercdrive.fr/', LeclercCrawler, LeclercParser, LeclercDatabaseHelper) def get_list_stores(self, code): """ This method gets a list of stores given an area code Input : - code (string): from '01' to '95' Output : - stores : [{ 'name': '...', 'url' }] """ when i try to